DEV Community

[Comment from a deleted post]
Collapse
 
gosukiwi_20 profile image
Federico Ramirez

Why use map if you will not use the return value? forEach will do in that case.

You could also use reduce:

[1, 2, 3, 1, 3].reduce(function (accu, curr) {
    if (!accu.includes(curr)) accu.push(curr);
    return accu;
}, [])

The filter solution is clever 😜