Write a function that accepts two or more arrays and returns a new array of unique values in the order of the array originally provided.

my idea is like this: put all the incoming arrays into a new array, and then traverse the new array to remove duplicates, but there are the following problems:

    function tick(){
        var result=[];
        for(var i=0;i<arguments.length;iPP){
            result=result.concat(arguments[i]);
        }
        for(var j=0;j<result.length;jPP){
            var index=-1;
            var flag=true;
            while(index=(result.indexOf(result[j],index+1))!==-1){
                if(flag){
                    flag=false;
                    continue;
                }else{//indextrue1
                    result.splice(index,1);
                }
            }

        }
        return result;
    }
Mar.04,2021

you should put
index= (result.indexOf (result [j], index+1))
in parentheses
otherwise assign the following Boolean to index


The

logical operator has a higher priority than the assignment operator, so the while condition is to perform logical operations first and then assign values, so the value of index can only be true or false , while false will exit the loop, so the value of index is true every time.

what you want is to assign a value before performing a logical operation, so just change the loop condition:

while((index=result.indexOf(result[j],index+1)) !== -1) {
  // ...
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b38b4d-2c11d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b38b4d-2c11d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?