Skip to content

Instantly share code, notes, and snippets.

@the-creature
Last active October 8, 2017 16:31
Show Gist options
  • Save the-creature/d7ab3941b0f75638b9884730a36f6287 to your computer and use it in GitHub Desktop.
Save the-creature/d7ab3941b0f75638b9884730a36f6287 to your computer and use it in GitHub Desktop.
ES6 filter and map basic
const numbers = [1,2,3,4,5,6,7,8,9,10];
const getEvenNumbers = numbers.filter(n => n % 2 === 0);
getEvenNumbers // [2, 4, 6, 8, 10]
const double = getEvenNumbers.map(n => n * 2);
double // [4, 8, 12, 16, 20]
numbers // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment