Files
30-seconds-of-code/snippets/similarity.md
Isabelle Viktoria Maciohsek 27c168ce55 Bake date into snippets
2021-06-13 13:55:00 +03:00

461 B

title, tags, firstSeen, lastUpdated
title tags firstSeen lastUpdated
similarity array,math,beginner 2017-12-17T16:41:31+02:00 2020-10-22T20:24:30+03:00

Returns an array of elements that appear in both arrays.

  • Use Array.prototype.includes() to determine values that are not part of values.
  • Use Array.prototype.filter() to remove them.
const similarity = (arr, values) => arr.filter(v => values.includes(v));
similarity([1, 2, 3], [1, 2, 4]); // [1, 2]