Created
February 9, 2019 12:36
-
-
Save lxm7/64951f569264414d67ec64824297c1c4 to your computer and use it in GitHub Desktop.
Merge 2 arrays v.efficiently set against the match of one field from one and one field form the other set. Maintain properties from both
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
const rootResolvers = { | |
Query: { | |
coins: async (_, { limit, offset }) => { | |
const initialLimit = process.env.LIMIT || limit; | |
const initialOffset = offset || 0; | |
const cmc = await fetchCmcListFn(initialLimit, initialOffset); | |
const cc = await fetchCcListFn(); | |
const coinListWithCcId = lodash(cmc) // start sequence | |
.keyBy('symbol') // create a dictionary of the 1st array | |
.merge(lodash.keyBy(cc, 'Symbol')) // create a dictionary of the 2nd array, and merge it to the 1st | |
.values() // turn the combined dictionary to array | |
.value() // get the value (array) out of the sequence | |
.filter((coin) => typeof coin.cmc_rank !== 'undefined'); // remove coins without rank value | |
return coinListWithCcId; | |
}, | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment