Skip to content

Commit

Permalink
# Final Refactoring
Browse files Browse the repository at this point in the history
Now that our tests are green and we're satisfied with the overall shape
of our final solution, we can do some final refactoring.

Using the underrated [tilde
operator](http://stackoverflow.com/a/5971668), we can simplify our
`seen` increment step and merge it onto the same line as the comparison
against `x`. Next, we can leverage some ES6 syntax sugar to consolidate
our `filter` lambda onto a single line.
  • Loading branch information
pcorey committed Jul 2, 2016
1 parent 775ef33 commit 0a86271
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
export function deleteNth(arr,x){
let seen = {};
return arr.filter((num) => {
seen[num] = (seen[num] || 0) + 1;
return seen[num] <= x;
});
return arr.filter((num) => (seen[num] = ~~seen[num] + 1) <= x);
}

0 comments on commit 0a86271

Please sign in to comment.