Hello,
Sorted Union
Could you give me an explanation about:
uniqueArray = concatArr.filter(function(item, pos) {
return concatArr.indexOf(item) == pos;
});
In this code:
function uniteUnique() {
var concatArr = [];
var i = 0;
while (arguments[i]) {
concatArr = concatArr.concat(arguments[i]);
i++;
}
uniqueArray = concatArr.filter(function(item, pos) {
return concatArr.indexOf(item) == pos;
});
return uniqueArray;
}
// test here
uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);
I never seen using the index argument in a filter callback until now. My problem is I think that concatArr.indexOf(item)
will be always egal to his pos
.
Where is my mistake ?