Last active
July 14, 2021 08:02
-
-
Save kpunith8/55ebcd3e5e10cb0c03d5165cfd3276a8 to your computer and use it in GitHub Desktop.
Keep only latest updated docs using lodash and keep unique entries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const lastUpdatedEngines = | |
_.map( | |
_.filter( | |
_.groupBy(actualData, 'engine'), // Group each engine | |
status => _.size(status) > 1 // Look for arrays having more than one entry | |
), | |
engines => { | |
const lastUpdatedEngine = engines.reduce((a, b) => | |
new Date(a?.updatedAt) > new Date(b?.updatedAt) ? a : b // compare the updatedAt for each engine and pick the latest | |
) | |
return lastUpdatedEngine | |
} | |
) | |
const uniqueUpdatedEngines = _.unionBy(lastUpdatedEngines, actualData, 'engine') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment