Skip to content

Instantly share code, notes, and snippets.

@chriswrightdesign
Last active June 23, 2017 06:52
Show Gist options
  • Save chriswrightdesign/20c318a047ddbc3a0ae4c46e91cc86e1 to your computer and use it in GitHub Desktop.
Save chriswrightdesign/20c318a047ddbc3a0ae4c46e91cc86e1 to your computer and use it in GitHub Desktop.
Example list of objects
const getValue = property => obj => obj && obj[property];
// Example List of users
const users = [{
name: 'sarah',
id: '12345',
country: 'Australia',
},
{
name: 'bob',
id: '34325',
country: 'New Zealand',
},
{
name: 'Sam',
id: '42524',
country: 'Australia',
},
{
name: 'Roger',
country: 'USA',
id: '314135'
}];
users.map(getValue('id'));
// result: ['12345', '34325', '42524', '314135']
/**
Every array value is being passed a function - the result of getValue('id')
which looks like this (obj) => obj && obj[property];
it has retained value ('id') from the outter call
which then returns '12345', '34325', '42524', '314135'
**/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment