Hilbert curve: Difference between revisions
Content added Content deleted
m (→JS Functional) |
m (→JS Functional) |
||
Line 1,817: | Line 1,817: | ||
return Boolean(n) ? ( |
return Boolean(n) ? ( |
||
take(n)(iterate(go)(seed)) |
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 |
||
// |
// 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 |
||
n = Math.min(length(xs), length(ys)), |
|||
as = take( |
as = take(n)(xs), |
||
bs = take( |
bs = take(n)(ys); |
||
return Array.from({ |
return Array.from({ |
||
length: |
length: n |
||
}, (_, i) => f(as[i], bs[i])); |
}, (_, i) => f(as[i], bs[i])); |
||
}; |
}; |