Array.diff hero

This commit is contained in:
2019-11-29 18:53:44 +01:00
parent fb8c57dd17
commit 2c4b7f8f3f

View File

@@ -0,0 +1,15 @@
// https://www.codewars.com/kata/array-dot-diff-hero
function array_diff_very_fast(a, b) {
const diff = [];
const set = new Set();
for (let i = 0; i < b.length; ++i) {
set.add(b[i]);
}
for (let i = 0; i < a.length; ++i) {
if (!set.has(a[i])) {
diff.push(a[i]);
}
}
return diff;
}