September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -1,20 +1,25 @@
(() => {
'use strict';
// SUM OF A SERIES -------------------------------------------------------
// seriesSum :: Num a => (a -> a) -> [a] -> a
const seriesSum = (f, xs) =>
xs.reduce((a, x) => a + f(x), 0);
foldl((a, x) => a + f(x), 0, xs);
// GENERIC ------------------------------------------
// GENERIC ---------------------------------------------------------------
// range :: Int -> Int -> [Int]
const range = (m, n) =>
// enumFromToInt :: Int -> Int -> [Int]
const enumFromTo = (m, n) =>
Array.from({
length: Math.floor(n - m) + 1
}, (_, i) => m + i);
// TEST ----------------------------------------------
// foldl :: (b -> a -> b) -> b -> [a] -> b
const foldl = (f, a, xs) => xs.reduce(f, a);
return seriesSum(x => 1 / (x * x), range(1, 1000));
// TEST ------------------------------------------------------------------
return seriesSum(x => 1 / (x * x), enumFromTo(1, 1000));
})();