Reduce() method Javascript is stupid! cannot use accumulator.push() [SOLVED!]

Reduce() method Javascript is stupid! cannot use accumulator.push() [SOLVED!]
0

#1

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


#2

.concat() returns a new array, but .push() returns the length of the array.



#4

oh now im stupid. Thanks alot for fast reply, and your time. You are really a hero here! thank you! :tada: