js algorithm to find duplicate elements

Idea: // Push if the first one overlaps with all the following ones. Then the second...
details: it is the ratio of the first to the 234567th, not the first to the first.
Break when found; then the second to the 34567th

function duplicates(arr) {
    
    
    var arr1=arr.slice(0);
    var arr2=[];
    var d=0;
    for(var i=0;i<arr.length;i++)
        {
    
    
            //如果第一个与后面的所有比有重复就push。然后第二个...
             d=arr[i];
            for(var j=i+1;j<arr1.length-1;j++)
                {
    
    
                    if(d==arr1[j])
                        {
    
    
                            arr2.push(d);
                              break;
                           
                        }
                   
                }
        }
    return arr2.sort();
}

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_37805832/article/details/115216031