标签:turn color == from IV dedup code dup block
数组去重的方法
1 function dedupe(array){ 2 return Array.from(new Set(array)); 3 } 4 ? 5 dedupe([1,2,3,3])
1 let list = [1,2,4,3,2,3,5,6,7,8,7]; 2 ? 3 let result = list.sort().reduce((init,current) => { 4 if(init.length === 0 || init[init.length-1] !== current){ 5 init.push(current); 6 } 7 return init; 8 },[]); 9 ? 10 console.log(result);
1 let arr = [1,2,3,3,4,5,5]; 2 let unique = [...new Set(arr)]; 3 return unique 4 //[1,2,3,4,5]
标签:turn color == from IV dedup code dup block
原文地址:https://www.cnblogs.com/annika/p/9126966.html