
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));
// EXAMPLE
similarity([1, 2, 3], [1, 2, 4]); // [1, 2]