Created
January 10, 2019 15:01
-
-
Save Akiyamka/904c352cc98c2b7f1c2e50b2949353d4 to your computer and use it in GitHub Desktop.
Create array of unique entries in dataset (not deep)
This file contains hidden or 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
/** | |
* Create array of unique entries in dataset (not deep) | |
* @Example | |
* const data = [ { regionId: 123, indicatorId: 345 }, { regionId: 123, indicatorId: 345 }, { regionId: 678, indicatorId: 910 }] | |
* extractListFrom('regionId', 'indicatorId')(data); | |
*/ | |
export function extractListFrom(...args) { | |
const accum = args.reduce((ac, arg) => { ac[arg] = new Set(); return ac }, {}); | |
return data => data.reduce((acc, m) => { | |
Object.keys(acc).forEach(key => acc[key].add(m[key])) | |
return acc | |
}, accum) | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment