Created
June 13, 2017 18:09
-
-
Save wesbos/aa9b392835fd12af37828a4b5891f4a6 to your computer and use it in GitHub Desktop.
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 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