#10 | 2017-12-17 04:37:34
// https://rosettacode.org/wiki/Power_set
const powerset = xs => xs.reduceRight((a, x) => a.concat(a.map(y => [x].concat(y))), [[]])

如果让我写,只能写出这样的:

const powerset = arr => Array(2 ** arr.length).fill(0).map((_, i) => i)
  .map(v => arr.filter((_, i) => (v >> i) % 2))
  // .map(v => v.toString(2).padStart(arr.length, '0'))
  // .map(v => arr.filter((_, i) => v[i] === '1'))