Factorial and powerset

This commit is contained in:
Angelos Chalaris
2017-12-07 14:41:33 +02:00
parent be3c075f12
commit d336333f9e
3 changed files with 36 additions and 0 deletions

8
snippets/powerset.md Normal file
View File

@ -0,0 +1,8 @@
### Powerset
Use `reduce()` combined with `map()` to iterate over elements and combine into an array containing all combinations.
```js
var powerset = arr =>
arr.reduce( (a,v) => a.concat(a.map( r => [v].concat(r) )), [[]]);
```