From 8fb2ec55d8b3d05d53cb199c37047189bc6246a3 Mon Sep 17 00:00:00 2001 From: discotiger Date: Thu, 24 Oct 2019 13:01:56 -0700 Subject: [PATCH] add javascript example of powerset in one line --- CONTRIBUTORS.md | 5 +++++ javascript/discotiger_powerset.js | 3 +++ 2 files changed, 8 insertions(+) create mode 100644 javascript/discotiger_powerset.js diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index c1b7b34b..83678024 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -439,3 +439,8 @@ Name: [Antonio](https://github.com/toluwalope19)
Place: Nigeria
Coding Experience: Python and javaScript.
Email: tolubarca01@gmail.com
+ +Name:[Caden Mccauley](https://github.com/DiscoTiger)
+Place: United States
+Coding Experience: CS Student primarily focusing on Javascript and C++ +Email: caden.n.mccauley@gmail.com
diff --git a/javascript/discotiger_powerset.js b/javascript/discotiger_powerset.js new file mode 100644 index 00000000..4874e8ca --- /dev/null +++ b/javascript/discotiger_powerset.js @@ -0,0 +1,3 @@ +// generate the powerset (set of all subsets) of an arrays elements +// given [a,b] return [[],[a],[b],[a,b]] +const powerset = (input) => input.reduce((acc, cur) => acc.concat(acc.map(x => [...x,cur])),[[]]); \ No newline at end of file