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([[]])
|
||||
}
|
||||
|
||||
})();
|
||||
5
Task/Power-set/JavaScript/power-set-3.js
Normal file
5
Task/Power-set/JavaScript/power-set-3.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"[1,2,3] ->":[[], [3], [2], [2, 3], [1], [1, 3], [1, 2], [1, 2, 3]],
|
||||
"empty set ->":[[]],
|
||||
"set which contains only the empty set ->":[[], [[]]]
|
||||
}
|
||||
19
Task/Power-set/JavaScript/power-set-4.js
Normal file
19
Task/Power-set/JavaScript/power-set-4.js
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
(() => {
|
||||
'use strict';
|
||||
|
||||
// powerset :: [a] -> [[a]]
|
||||
const powerset = xs =>
|
||||
xs.reduceRight((a, x) => a.concat(a.map(y => [x].concat(y))), [
|
||||
[]
|
||||
]);
|
||||
|
||||
|
||||
// TEST
|
||||
return {
|
||||
'[1,2,3] ->': powerset([1, 2, 3]),
|
||||
'empty set ->': powerset([]),
|
||||
'set which contains only the empty set ->': powerset([
|
||||
[]
|
||||
])
|
||||
};
|
||||
})()
|
||||
3
Task/Power-set/JavaScript/power-set-5.js
Normal file
3
Task/Power-set/JavaScript/power-set-5.js
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{"[1,2,3] ->":[[], [3], [2], [2, 3], [1], [1, 3], [1, 2], [1, 2, 3]],
|
||||
"empty set ->":[[]],
|
||||
"set which contains only the empty set ->":[[], [[]]]}
|
||||
Loading…
Add table
Add a link
Reference in a new issue