First, on the pre – and post-increment

1. A ++ returns a and increments by 1

2.++ A increases by 1 and returns A

Case 3.

Case 1

var num=1;
var num2=++num + num++; ++num=2; Num = 2; Returns the num = 2
                        //num++: num=2; num++=2
console.log(num2)       // The result is 4
Copy the code

Case 2

var num=1;
var num2=num++ + num++;   //num++: num=1, num=2,num=2
                          //num++: num=2; num++=2,
console.log(num2)         // The result is 3
Copy the code

Example 3

var num=1;
var num2=++num + ++num;   Num =2,++num=2
                          //++num = 1; num++=3,
console.log(num2)         // The result is 5
Copy the code

Array deduplication

1. Core algorithm:

Iterate through the old array, then query the new array with the old array, if the element does not appear in the new array, add the element to the new array; Otherwise, it is not added

2. Determine whether the element exists:

Use the new array.indexof. If -1 is returned, the element does not exist in the new array

3. Code implementation

let arr=[12.34.46.1.2]
function unique(arr){
    let newArr=[];
    for(i=0; i<arr.length; i++){if(newArr.indexof(arr[i])==-1){ newArr.push(arr[i]); }}return newArr;
}
Copy the code

To be continued…