Skip to content

Instantly share code, notes, and snippets.

@matthewblewitt
Last active April 24, 2019 14:22
Show Gist options
  • Select an option

  • Save matthewblewitt/3ff1348ae53ba1e519c84cfcad352bcf to your computer and use it in GitHub Desktop.

Select an option

Save matthewblewitt/3ff1348ae53ba1e519c84cfcad352bcf to your computer and use it in GitHub Desktop.
Find duplicates in a array with array filter method
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const fibonacci = [0, 1, 1, 2, 3, 5, 8, 13];
const duplicates = numbers.filter(number => fibonacci.indexOf(number) !== -1);
console.log(duplicates); // [1, 2, 3, 5, 8]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment