安静不平静  

利用对象的属性不会重复这一特性,校验数组元素是否重复

 1 function distinct(a, b) {
 2     let arr = a.concat(b)
 3     let result = []
 4     let obj = {}
 5 
 6     for (let i of arr) {
 7         if (!obj[i]) {
 8             result.push(i)
 9             obj[i] = 1
10         }
11     }
12 
13     return result
14 }

转载  https://www.cnblogs.com/wisewrong/p/9642264.html

posted on 2019-09-11 16:04  安静不平静  阅读(264)  评论(0)    收藏  举报