TIL Finds the differences between arrays
POSTED ON:
TAGS: arrays javascript
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]
Related TILs
Tagged: arrays