Hilbert curve: Difference between revisions

Content added Content deleted
Line 1,817: Line 1,817:


return Boolean(n) ? (
return Boolean(n) ? (
take(n)(iterate(go)(seed)).slice(-1)[0]
take(n)(iterate(go)(seed))
.slice(-1)[0]
) : seed;
) : seed;
};
};
Line 1,917: Line 1,918:
// iterate :: (a -> a) -> a -> Gen [a]
// iterate :: (a -> a) -> a -> Gen [a]
const iterate = f =>
const iterate = f =>
// An infinite list of repeated
// An infinite list of repeated applications
// applications of f to x.
// of f, starting with the seed value x.
function* (x) {
function* (x) {
let v = x;
let v = x;
Line 1,962: Line 1,963:
xs => ys => {
xs => ys => {
const
const
lng = Math.min(length(xs), length(ys)),
n = Math.min(length(xs), length(ys)),
as = take(lng)(xs),
as = take(n)(xs),
bs = take(lng)(ys);
bs = take(n)(ys);


return Array.from({
return Array.from({
length: lng
length: n
}, (_, i) => f(as[i], bs[i]));
}, (_, i) => f(as[i], bs[i]));
};
};