Last Updated: February 25, 2016
·
383
· gnclmorais

Simplest ‘removeDuplicates’ in JavaScript Arrays

Other question I’ve found a lot in job interview questions, and this is the simplest implementation I’ve found:

[…].filter(function (val, idx, arr) {
    var firstIdx = arr.indexOf(val);
    return (idx === firstIdx) || (firstIdx === arr.lastIndexOf(val));
});