Skip to content

Commit

Permalink
Core: refactor diff to do less slow mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
izelnakri committed Jul 5, 2022
1 parent 033f35f commit cd84fe8
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/core/utilities.js
Expand Up @@ -43,18 +43,13 @@ export const performance = {

// Returns a new Array with the elements that are in a but not in b
export function diff (a, b) {
const result = a.slice();

for (let i = 0; i < result.length; i++) {
for (let j = 0; j < b.length; j++) {
if (result[i] === b[j]) {
result.splice(i, 1);
i--;
break;
}
return a.reduce((result, item) => {
if (!b.includes(item)) {
result.push(item);
}
}
return result;

return result;
}, []);
}

/**
Expand Down

0 comments on commit cd84fe8

Please sign in to comment.