Created
February 28, 2019 13:24
-
-
Save dmitryshelomanov/4373abb8d77af2b2b30aec21aaf2a12d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function buildNumber (number) { | |
return (op) => { | |
if (typeof op === 'function') { | |
return op(number) | |
} | |
return number | |
} | |
} | |
const zero = buildNumber(0) | |
const one = buildNumber(1) | |
const two = buildNumber(2) | |
const three = buildNumber(3) | |
const four = buildNumber(4) | |
const five = buildNumber(5) | |
const six = buildNumber(6) | |
const seven = buildNumber(7) | |
const eight = buildNumber(8) | |
const nine = buildNumber(9) | |
const plus = (x) => (y) => x + y | |
const minus = (x) => (y) => y - x | |
const times = (x) => (y) => x * y | |
const dividedBy = (x) => (y) => Math.floor(y / x) | |
console.assert(seven(times(five())) === 35) | |
console.assert(four(plus(nine())) === 13) | |
console.assert(eight(minus(three())) === 5) | |
console.assert(six(dividedBy(two())) === 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment