2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -0,0 +1,60 @@
(function () {
'use strict';
// arithmetic_mean :: [Number] -> Number
function arithmetic_mean(ns) {
return (
ns.reduce( // sum
function (sum, n) {
return (sum + n);
},
0
) / ns.length
);
}
// geometric_mean :: [Number] -> Number
function geometric_mean(ns) {
return Math.pow(
ns.reduce( // product
function (product, n) {
return (product * n);
},
1
),
1 / ns.length
);
}
// harmonic_mean :: [Number] -> Number
function harmonic_mean(ns) {
return (
ns.length / ns.reduce( // sum of inverses
function (invSum, n) {
return (invSum + (1 / n));
},
0
)
);
}
var values = [arithmetic_mean, geometric_mean, harmonic_mean]
.map(function (f) {
return f([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
}),
mean = {
Arithmetic: values[0], // arithmetic
Geometric: values[1], // geometric
Harmonic: values[2] // harmonic
}
return JSON.stringify({
values: mean,
test: "is A >= G >= H ? " +
(
mean.Arithmetic >= mean.Geometric &&
mean.Geometric >= mean.Harmonic ? "yes" : "no"
)
}, null, 2);
})();

View file

@ -0,0 +1,8 @@
{
"values": {
"Arithmetic": 5.5,
"Geometric": 4.528728688116765,
"Harmonic": 3.414171521474055
},
"test": "is A >= G >= H ? yes"
}

View file

@ -0,0 +1,32 @@
(() => {
// arithmeticMean :: [Number] -> Number
const arithmeticMean = xs =>
xs.reduce((sum, n) => sum + n, 0) / xs.length;
// geometricMean :: [Number] -> Number
const geometricMean = xs =>
Math.pow(xs.reduce((product, x) => product * x, 1), 1 / xs.length);
// harmonicMean :: [Number] -> Number
const harmonicMean = xs =>
xs.length / xs.reduce((invSum, n) => invSum + (1 / n), 0);
// TEST
const values = [arithmeticMean, geometricMean, harmonicMean]
.map(f => f([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])),
mean = {
Arithmetic: values[0],
Geometric: values[1],
Harmonic: values[2]
};
return JSON.stringify({
values: mean,
test: `is A >= G >= H ? ${mean.Arithmetic >= mean.Geometric &&
mean.Geometric >= mean.Harmonic ? "yes" : "no"}`
}, null, 2);
})();

View file

@ -0,0 +1,8 @@
{
"values": {
"Arithmetic": 5.5,
"Geometric": 4.528728688116765,
"Harmonic": 3.414171521474055
},
"test": "is A >= G >= H ? yes"
}

View file

@ -1,21 +0,0 @@
function arithmetic_mean(ary) {
var sum = ary.reduce(function(s,x) {return (s+x)}, 0);
return (sum / ary.length);
}
function geometic_mean(ary) {
var product = ary.reduce(function(s,x) {return (s*x)}, 1);
return Math.pow(product, 1/ary.length);
}
function harmonic_mean(ary) {
var sum_of_inv = ary.reduce(function(s,x) {return (s + 1/x)}, 0);
return (ary.length / sum_of_inv);
}
var ary = [1,2,3,4,5,6,7,8,9,10];
var A = arithmetic_mean(ary);
var G = geometic_mean(ary);
var H = harmonic_mean(ary);
print("is A >= G >= H ? " + (A >= G && G >= H ? "yes" : "no"));