Skip to content

Instantly share code, notes, and snippets.

@thebopshoobop
Created February 12, 2018 05:34
Show Gist options
  • Save thebopshoobop/093e8e4daea500a06378473bd4b42272 to your computer and use it in GitHub Desktop.
Save thebopshoobop/093e8e4daea500a06378473bd4b42272 to your computer and use it in GitHub Desktop.
const simplify = sample => {
let deDup = [];
for (let current of sample) {
deDup[current] = true;
}
return Object.keys(deDup)
.map(i => +i)
.sort((a, b) => a - b);
};
@thebopshoobop
Copy link
Author

Now with even more counting sort. This one is even faster, somehow.

const simplify = sample => {
  let deDup = [];
  for (let current of sample) {
    deDup[current] = true;
  }

  let result = [];
  for (let current in deDup) {
    result.push(+current);
  }
  return result;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment