Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
28
Task/Factorial/JavaScript/factorial-7.js
Normal file
28
Task/Factorial/JavaScript/factorial-7.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
(() => {
|
||||
'use strict';
|
||||
|
||||
// factorial :: Int -> Int
|
||||
const factorial = n =>
|
||||
enumFromTo(1, n)
|
||||
.reduce(product, 1);
|
||||
|
||||
|
||||
const test = () =>
|
||||
factorial(18);
|
||||
// --> 6402373705728000
|
||||
|
||||
|
||||
// GENERIC FUNCTIONS ----------------------------------
|
||||
|
||||
// product :: Num -> Num -> Num
|
||||
const product = (a, b) => a * b;
|
||||
|
||||
// range :: Int -> Int -> [Int]
|
||||
const enumFromTo = (m, n) =>
|
||||
Array.from({
|
||||
length: (n - m) + 1
|
||||
}, (_, i) => m + i);
|
||||
|
||||
// MAIN ------
|
||||
return test();
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue