BranceLee / ES6-NoteBook

I am learn ES6 as a fresh man ,there are some notes when I am learning it
0 stars 0 forks source link

数组的交并补总结 #7

Open BranceLee opened 6 years ago

BranceLee commented 6 years ago
cosnt a=[1,1,1,1,2,3,4,4,5] ;
const b=[1,2,3] ;

const a1=new Set(a) // 变集合
const b1=new Set(b) // ...

并: const U=new Set([...a1,...b1]) //

交: const N=new Set([...a1].filter(x=>b1.has(x))) // 【...a1】转数组具有调filter ,

补: const R=new Set([...a1].filter(x=>!b1.has(x)))

BranceLee commented 6 years ago
const a=[1,2,2,3]
const a1={...a} //{0:1,1:2,2:2,3:3}

拓展:

Object.entries(Level).forEach(([level, config]) => { //顺带解构赋值了 const { getRoad, ipCord, ipDirection, targetCord } = config; })