If you are going to use filter, it'd be better to make the filter method pure.
filter
[1,2,1,2,35,3,4].filter((v, i, arr) => arr.indexOf(v) === i)
That way, you can extract the function out:
function makeUniq(v, i, arr) { return arr.indexOf(v) === i; } [1,2,3,4,4,3,4].filter(makeUniq); [6,7,3,4,6,7,7].filter(makeUniq);
Also, map is supposed to be pure, use forEach to do mutations instead.
map
forEach
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
If you are going to use
filter
, it'd be better to make the filter method pure.That way, you can extract the function out:
Also,
map
is supposed to be pure, useforEach
to do mutations instead.