封装方法之数组降维去重排序--记录

      //数组降维、排序、去重。
 
        function reduceSortUniq(arr) {

 

 
            let newarr = [];
 
            arr.flat(Infinity).sort().forEach(function (item) {
 
                if (!newarr.includes(item)) {
                    newarr.push(item)
                }
            })
 
            return newarr;  
        }

 

        let arr = [1, 3, 2, [2, 6, 7, [9, 3, 5, [6, 4, 2, [1, 8]]]]]
        console.log(reduceSortUniq(arr));              //调用传参

 

posted @ 2021-01-05 20:39  为了招猫遛狗养金鱼  阅读(73)  评论(0)    收藏  举报