Tell us what’s happening:
I just finished the test, but when I consulted other ways, I encountered a code using the filter method. And after reading the code I have a question like this:
Your code so far
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]);
What role does the ‘pos’ parameter have in the filter function and what is its value and how does it work?
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/sorted-union