Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,11 @@
function sumsq(array) {
var sum = 0;
var i, iLen;
for (i = 0, iLen = array.length; i < iLen; i++) {
sum += array[i] * array[i];
}
return sum;
}
alert(sumsq([1,2,3,4,5])); // 55

View file

@ -0,0 +1,10 @@
function sumsq(array) {
var sum = 0,
i = array.length;
while (i--) sum += Math.pow(array[i], 2);
return sum;
}
alert(sumsq([1,2,3,4,5])); // 55

View file

@ -0,0 +1 @@
Functional.reduce("x+y*y", 0, [1,2,3,4,5])

View file

@ -0,0 +1 @@
[3,1,4,1,5,9].map(function (n) { return Math.pow(n,2); }).reduce(function (sum,n) { return sum+n; });

View file

@ -0,0 +1,35 @@
(() => {
'use strict';
// sumOfSquares :: Num a => [a] -> a
const sumOfSquares = xs =>
sum(xs.map(squared));
// sumOfSquares2 :: Num a => [a] -> a
const sumOfSquares2 = xs =>
xs.reduce((a, x) => a + squared(x), 0);
// ---------------------- TEST -----------------------
const main = () => [
sumOfSquares,
sumOfSquares2
].map(
f => f([3, 1, 4, 1, 5, 9])
).join('\n');
// --------------------- GENERIC ---------------------
// squared :: Num a => a -> a
const squared = x =>
Math.pow(x, 2);
// sum :: [Num] -> Num
const sum = xs =>
// The numeric sum of all values in xs.
xs.reduce((a, x) => a + x, 0);
// MAIN ---
return main();
})();