Update powerset.md

This commit is contained in:
Angelos Chalaris
2021-09-27 15:28:26 +03:00
committed by GitHub
parent 33ee1d0e12
commit 4cb96fd264

View File

@ -2,7 +2,7 @@
title: powerset
tags: math,algorithm,beginner
firstSeen: 2017-12-07T14:41:33+02:00
lastUpdated: 2020-12-28T13:49:24+02:00
lastUpdated: 2021-09-27T15:27:07+02:00
---
Returns the powerset of a given array of numbers.
@ -11,9 +11,9 @@ Returns the powerset of a given array of numbers.
```js
const powerset = arr =>
arr.reduce((a, v) => a.concat(a.map(r => [v].concat(r))), [[]]);
arr.reduce((a, v) => a.concat(a.map(r => r.concat(v))), [[]]);
```
```js
powerset([1, 2]); // [[], [1], [2], [2, 1]]
powerset([1, 2]); // [[], [1], [2], [1, 2]]
```