-
-
Save jjsub/2188f54bb9f933a5162bcf1401746d27 to your computer and use it in GitHub Desktop.
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 countryCodes = { | |
US: 'United States', | |
CA: 'Canada', | |
NG: 'Nigeria', | |
GB: 'United Kingdom', | |
}; | |
const sales = [ | |
{ code: 'US', count: 233 }, | |
{ code: 'CA', count: 200 }, | |
{ code: 'GB', count: 150 }, | |
{ code: 'NG', count: 111 }, | |
]; | |
const salesMix = sales.map(sale => { | |
return { | |
...sale, // object spread takes does a shallow copy of the sale object | |
country: countryCodes[sale.code] | |
}; | |
}); | |
// or the hotshot way with implicit return: | |
const salesMixHotShot = sales.map(sale => ({...sale, country: countryCodes[sale.code] })); | |
console.table(salesMix); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment