similarity
Returns an array of elements that appear in both arrays.
- Use
Array.prototype.includes()to determine values that are not part ofvalues. - 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]