Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,59 @@
(function () {
'use strict';
// angloDuration :: Int -> String
function angloDuration(intSeconds) {
return zip(
weekParts(intSeconds),
['wk', 'd', 'hr', 'min','sec']
)
.reduce(function (a, x) {
return a.concat(x[0] ? (
[(x[0].toString() + ' ' + x[1])]
) : []);
}, [])
.join(', ');
}
// weekParts :: Int -> [Int]
function weekParts(intSeconds) {
return [undefined, 7, 24, 60, 60]
.reduceRight(function (a, x) {
var intRest = a.remaining,
intMod = isNaN(x) ? intRest : intRest % x;
return {
remaining:(intRest - intMod) / (x || 1),
parts: [intMod].concat(a.parts)
};
}, {
remaining: intSeconds,
parts: []
})
.parts
}
// GENERIC ZIP
// zip :: [a] -> [b] -> [(a,b)]
function zip(xs, ys) {
return xs.length === ys.length ? (
xs.map(function (x, i) {
return [x, ys[i]];
})
) : undefined;
}
// TEST
return [7259, 86400, 6000000]
.map(function (intSeconds) {
return intSeconds.toString() +
' -> ' + angloDuration(intSeconds);
})
.join('\n');
})();

View file

@ -0,0 +1,48 @@
(() => {
"use strict";
// ---------------- COMPOUND DURATION ----------------
// compoundDuration :: [String] -> Int -> String
const compoundDuration = labels =>
nSeconds => weekParts(nSeconds)
.map((v, i) => [v, labels[i]])
.reduce((a, x) =>
a.concat(
x[0] ? [
`${x[0]} ${x[1] || "?"}`
] : []
), []
)
.join(", ");
// weekParts :: Int -> [Int]
const weekParts = nSeconds => [0, 7, 24, 60, 60]
.reduceRight((a, x) => {
const
r = a[0],
mod = x !== 0 ? r % x : r;
return [
(r - mod) / (x || 1),
[mod, ...a[1]]
];
}, [nSeconds, []])[1];
// ---------------------- TEST -----------------------
// main :: IO ()
const main = () => {
const localNames = ["wk", "d", "hr", "min", "sec"];
return [7259, 86400, 6E6]
.map(nSeconds =>
`${nSeconds} -> ${
compoundDuration(localNames)(nSeconds)
}`).join("\n");
};
// MAIN ---
return main();
})();