Skip to content

Commit

Permalink
Optimize arrayUnique (chartjs#6871)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle authored and etimberg committed Dec 31, 2019
1 parent 102a311 commit ab39286
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/scales/scale.time.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,18 @@ function sorter(a, b) {
}

function arrayUnique(items) {
const hash = {};
const out = [];
let i, ilen, item;
const set = new Set();
let i, ilen;

for (i = 0, ilen = items.length; i < ilen; ++i) {
item = items[i];
if (!hash[item]) {
hash[item] = true;
out.push(item);
}
set.add(items[i]);
}

if (set.size === ilen) {
return items;
}

return out;
return [...set];
}

/**
Expand Down

0 comments on commit ab39286

Please sign in to comment.