Skip to content

Instantly share code, notes, and snippets.

@krohne
Created October 18, 2016 15:27
Show Gist options
  • Save krohne/2885dc8b4710faf32f9a8102f4869c69 to your computer and use it in GitHub Desktop.
Save krohne/2885dc8b4710faf32f9a8102f4869c69 to your computer and use it in GitHub Desktop.
Given an array of n integers (example: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, 112, 113] ), // remove all odd numbers, leaving only the even numbers.
// given an array of n integers (example: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, 112, 113] ),
// remove all odd numbers, leaving only the even numbers.
const x = [
-Math.MAX_VALUE, -113, -112, -100, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, -Math.MIN_VALUE, -0,
0, Math.MIN_VALUE, 1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, 112, 113, Math.MAX_VALUE
];
console.log(x.filter( n => { return ( n % 2 === 0); }));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment