function uniteUnique(arr) {
var newArr=[];
for(index in arguments){
//console.log(arguments[index]);
// i got all args in arr, now i want to sorted the unique
newArr= newArr.concat(arguments[index]); // concat arguments array save it to newArr
}
newArr.unshift([newArr[0]]); // create initial accumulator
var completeNew= newArr.reduce(function(acc,curVal,curIndex){
if(acc.indexOf(curVal)<0){
return acc.concat(curVal); // why i cant use acc.push() method here! but acc.concat works
}
else{
return acc;
}
});
return completeNew;
}
uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);
In reduce method, why it only works when acc.concat(curVal) but not acc.push(). I also debugged it but cant find any mistake here!. Please help me, sorry for my english, also my messy code. Thanks