Array similarity

JavaScript, Array, Math · Oct 22, 2020

Returns an array of elements that appear in both arrays.

const similarity = (arr, values) => arr.filter(v => values.includes(v));
similarity([1, 2, 3], [1, 2, 4]); // [1, 2]

More like this

  • JavaScript Math

    A snippet collection of math helpers and algorithms implemented in JavaScript.

    Collection · 95 snippets

  • Mapped array intersection

    Returns the elements that exist in both arrays, after applying the provided function to each array element of both.

    JavaScript, Array · Oct 20, 2020

  • Mapped array symmetric difference

    Returns the symmetric difference between two arrays, after applying the provided function to each array element of both.

    JavaScript, Array · Oct 22, 2020

  • Mapped array difference

    Returns the difference between two arrays, after applying the provided function to each array element of both.

    JavaScript, Array · Oct 19, 2020