Files
30-seconds-of-code/snippets/similarity.md
Isabelle Viktoria Maciohsek 5cb69e3c5c Update snippet descriptions
2020-10-22 20:24:30 +03:00

385 B

title, tags
title tags
similarity array,math,beginner

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]