数组去重:
es5
[1,2,3,1,'a',1,'a'].filter(function(ele,index,array){ return index===array.indexOf(ele)})
es6
[...new Set([1,2,3,1,'a',1,'a'])]
数组摊平
const deepFlatten = arr => [].concat(...arr.map(v => Array.isArray(v) ? deepFlatten(v) : v));
求子集
//powerSet([1,2]) -> [[],[2],[1],[1,2]]function powerSet(arr = []) { if (arr.length === 0) { return [[]]; } else { let head = arr.shift(); let temp = powerSet(arr); return temp.concat(temp.map((e) => [head].concat(e))); } }