Skip to content

Instantly share code, notes, and snippets.

@aderaaij
Last active November 12, 2017 15:32
Show Gist options
  • Save aderaaij/88c217ce78e4c421e9d6cbe73d192d61 to your computer and use it in GitHub Desktop.
Save aderaaij/88c217ce78e4c421e9d6cbe73d192d61 to your computer and use it in GitHub Desktop.
Arrow function examples for return and filter, from https://es6.io. 1. Return an object with winners, the race they participate in and their finishing place based on the order of the array. Note that the second argument is shorthand, when both the name and value are equal. Also note the braces around the curly brackets to immediately invoke a re…
const race = '100m Dash';
const winners = ['Hunter Gath', 'Singa Song', 'Imda Bos'];
// Return an object with winners, the race they participate in and their
// finishing place based on the order of the array
// Note that the second argument is shorthand, when both the name and value
// are equal
const win = winners.map((winner, i) => ({ name: winner, race, place: i+1}));
console.log(win);
const ages = [12, 10, 20, 49, 70, 86, 96, 83, 98, 66, 77, 55, 45];
// Filter an age
const old = ages.filter(age => age >= 60);
console.log(old);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment