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,12 +1,19 @@
function nreps(s, n) {
var o = '';
if (n < 1) return o;
while (n > 1) {
if (n & 1) o += s;
n >>= 1;
s += s;
}
return o + s;
}
(() => {
'use strict';
nreps('ha', 50000);
// replicate :: Int -> String -> String
const replicate = (n, s) => {
let v = [s],
o = [];
if (n < 1) return o;
while (n > 1) {
if (n & 1) o = o + v;
n >>= 1;
v = v + v;
}
return o.concat(v);
};
return replicate(5000, "ha")
})();

View file

@ -0,0 +1,27 @@
(() => {
'use strict';
// repeat :: Int -> String -> String
const repeat = (n, s) =>
concat(replicate(n, s));
// GENERIC FUNCTIONS ------------------------------------------------------
// concat :: [[a]] -> [a] | [String] -> String
const concat = xs =>
xs.length > 0 ? (() => {
const unit = typeof xs[0] === 'string' ? '' : [];
return unit.concat.apply(unit, xs);
})() : [];
// replicate :: Int -> a -> [a]
const replicate = (n, x) =>
Array.from({
length: n
}, () => x);
// TEST -------------------------------------------------------------------
return repeat(5, 'ha');
})();