![Return an array of elements that appear in both arrays](https://javascriptsource.com/wp-content/uploads/2022/07/Return-an-array-of-elements-that-appear-in-both-arrays-702x526.jpg)
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]