Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize arrayUnique #6871

Merged
merged 4 commits into from
Dec 31, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 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 = [];
const set = new Set();
let i, ilen, item;

for (i = 0, ilen = items.length; i < ilen; ++i) {
item = items[i];
if (!hash[item]) {
hash[item] = true;
out.push(item);
}
set.add(item, true);
kurkle marked this conversation as resolved.
Show resolved Hide resolved
}
if (set.size === ilen) {
return items;
}

return out;
return Array.from(set);
benmccann marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down