Binary digits: Difference between revisions
Content added Content deleted
No edit summary |
m (→JS ES6: Tidied) |
||
Line 2,767: | Line 2,767: | ||
===ES6=== |
===ES6=== |
||
The simplest |
The simplest showBinary (or showIntAtBase), using default digit characters, would use JavaScript's standard String.toString(base): |
||
<lang JavaScript>(() => { |
<lang JavaScript>(() => { |
||
"use strict"; |
|||
⚫ | |||
// showIntAtBase_ :: // Int -> Int -> String |
|||
const showIntAtBase_ = (base, n) => (n) |
|||
⚫ | |||
// |
// showBinary :: Int -> String |
||
const |
const showBinary = n => |
||
showIntAtBase_(2)(n); |
|||
⚫ | |||
// |
// showIntAtBase_ :: // Int -> Int -> String |
||
const |
const showIntAtBase_ = base => |
||
⚫ | |||
// map :: (a -> b) -> [a] -> [b] |
|||
const map = (f, xs) => xs.map(f); |
|||
// unlines :: [String] -> String |
|||
⚫ | |||
⚫ | |||
// show :: a -> String |
|||
const |
const main = () => [5, 50, 9000] |
||
.map(n => `${n} -> ${showBinary(n)}`) |
|||
⚫ | |||
⚫ | |||
// MAIN --- |
|||
return main(); |
|||
n => intercalate(' -> ', [show(n), showBin(n)]), |
|||
[5, 50, 9000] |
|||
)); |
|||
})();</lang> |
})();</lang> |
||
{{Out}} |
{{Out}} |