We said yesterday two times the method of linear search, this time we will say two times linear array de-heavy usage.
//first set up an array vararr = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 5, 5, 6, 7, 8, 9, 0, 0, 3, 4, 5]; //Let's wrap up a function to calculate the calculation of the array's weight. functionFindinarr (arr,n) {//Comparison of data for(vari = 0; i < arr.length; i++){ //do not see that the IF statement does not think so, in fact, it is possible if(Arr[i] = = N)return true; } return false; } //encapsulates a function of a two-point de-weight functionRemovedup (arr, S, e) {//Let's start by judging if it's wrong . if(S >e) { return false; }Else if(s = =e) { //If there is only one data in the array, return a number. return[Arr[s]]; } //Calculate intermediate Values varc = Math.floor ((s + e)/2); //divide the data into two varL =Removedup (arr, S, c); varr = Removedup (arr, C + 1, E); //Start Cycle comparison for(vari = 0; i < r.length; i++){ if(!Findinarr (L,r[i])) {L.push (r[i]); } } //finally returns the computed array returnl; } //send results to the consoleConsole.log (Removedup (arr, 0, arr.length-1));
So that we can do the deduplication step in the array, with two times linear is a lot of data can be quickly analyzed. If you are interested, you can try it.
Two-part linear array de-weight