2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
21
Task/Power-set/JavaScript/power-set-2.js
Normal file
21
Task/Power-set/JavaScript/power-set-2.js
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
(function () {
|
||||
|
||||
// translating: powerset = foldr (\x acc -> acc ++ map (x:) acc) [[]]
|
||||
|
||||
function powerset(xs) {
|
||||
return xs.reduceRight(function (a, x) {
|
||||
return a.concat(a.map(function (y) {
|
||||
return [x].concat(y);
|
||||
}));
|
||||
}, [[]]);
|
||||
}
|
||||
|
||||
|
||||
// TEST
|
||||
return {
|
||||
'[1,2,3] ->': powerset([1, 2, 3]),
|
||||
'empty set ->': powerset([]),
|
||||
'set which contains only the empty set ->': powerset([[]])
|
||||
}
|
||||
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue