Files
iNaturalistReactNative/src/components/PhotoImporter/helpers/groupPhotoHelpers.js
2025-12-22 18:26:38 -08:00

17 lines
542 B
JavaScript

// @flow
const sortByTime = array => array.sort( ( a, b ) => b.timestamp - a.timestamp );
const flattenAndOrderSelectedPhotos = ( selectedObservations: ?Object[] ): Object[] => {
// combine selected observations into a single array
let combinedPhotos = [];
selectedObservations?.forEach( obs => {
combinedPhotos = combinedPhotos.concat( obs.photos );
} );
// sort selected observations by timestamp and avoid duplicates
return [...new Set( sortByTime( combinedPhotos ) )];
};
export default flattenAndOrderSelectedPhotos;