Today I Learned - Rocky Kev

TIL Finds the differences between arrays

POSTED ON:

TAGS:

Finds the differences between arrays

const differenceInArrays = (array1, array2) =>  {
const set = new Set(array2);
return array1.filter(x => !set.has(x));
};
differenceInArrays(["apple", "orange", "banana"], ["apple", "orange", "mango"]); // ["banana"]
differenceInArrays([10, 12, 5], [66, 10, 6]); // [12, 5]

Via
21 Useful JS snippets


Related TILs

Tagged:

TIL mutations and how to sort without mutating

Mutation isn't bad. It CAN cause side effects and ruin your life. There's times when you want to have your objects mutate. For everything else, switch to functional programming and passing the data.

TIL a clean way to add classes based on the page in Vue

If your pages exist in a array, use the includes() to check.

TIL Finds the differences between arrays

Finds the differences between arrays