Array.diff hero
This commit is contained in:
15
array-dot-diff-hero/index.js
Normal file
15
array-dot-diff-hero/index.js
Normal 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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user