Polar Aurora

Time:2022-1-3
The first method uses the reduce method, which is determined by the incoming content
Var ARRS = ['a', 'a','d ',' C ',' f ','d', 'I', 'I', 'he', 2,2,5,4,6,8];
function a(){
    return  arrs.reduce( function(prev:any,next:any){
        console.log(prev);
        console.log(next);
        prev[next]=(prev[next]+1) || 1;

        return prev;
    },{})
}

console.log(a());

The second double cycle comparison method

Implementation theory: define an empty array, the first loop loop array, and then create a variable to store the current value, and then create a variable to store the occurrence times. Compare the data of the second loop with the data of the first loop. If the number of times variable exists, add 1, and the compared value will become – 1. Finally, the current value is not equal to – 1 Save to new array

Var arr = ['a', 'a','d ',' C ',' f ','d', 'I', 'I', 'he', 2,2,5,4,6,8];
function arrCheck(arr:any){
    var newArr = [];
    for(var i=0;i

The third is the simplest

Implementation theory: define an empty object, loop the array, judge if there is this property in the object, add 1 to the value (use hasownproperty), if not, add this property to the object, and set the initial value to 1

Var arr = ['a', 'a','d ',' C ',' f ','d', 'I', 'I', 'he', 2,2,5,4,6,8];
var obj={};
 for(let i=0;i

 

Recommended Today

Vue2 technology finishing 3 – Advanced chapter – update completed

3. Advanced chapter preface Links to basic chapters:https://www.cnblogs.com/xiegongzi/p/15782921.html Link to component development:https://www.cnblogs.com/xiegongzi/p/15823605.html 3.1. Custom events of components 3.1.1. Binding custom events There are two implementation methods here: one is to use v-on with vuecomponent$ Emit implementation [PS: this method is a little similar to passing from child to parent]; The other is to use ref […]