Files
30-seconds-of-code/javascript/snippets/similarity.md
2023-05-01 22:35:56 +03:00

459 B

title, type, tags, cover, dateModified
title type tags cover dateModified
Array similarity snippet
array
math
dark-leaves-5 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]