Cantor set: Difference between revisions
→{{header|JavaScript}}: Tidied first version, updated its primitives.
(→{{header|JavaScript}}: Tidied first version, updated its primitives.) |
|||
Line 1,594:
{{Trans|Haskell}}
<lang JavaScript>(() => {
// --------------------- CANTOR ----------------------
const main = () => {▼
return [▼
[true, x]
})() : [▼
[bln, n]▼
];
};▼
const cantorLines = n =>▼
map(showCantor,▼
take(n,▼
▲ );
// ---------------------- TEST -----------------------
// main :: IO ()
const main = ()
([bln, n]) => replicate(n, bln ? '*' : ' '), xs▼
));▼
console.log(▼
);▼
▲ };
//
//
.join("");
// ---------------- GENERIC FUNCTIONS ----------------
// iterate :: (a -> a) -> a -> Gen [a]
function*
let v =
}▼
▲ };
// take :: Int -> [a] -> [a]
// take :: Int -> String -> String
const take =
// The first n elements of a list,
'GeneratorFunction' !== xs.constructor.constructor.name ? (▼
// string of characters, or stream.
xs => "GeneratorFunction" !== xs
xs.slice(0, n)
) : [].concat
length: n
}, () => {
const x = xs.next();
return x.done ? [] : [x.value];
}));
// MAIN ---
|