Skip to content

Instantly share code, notes, and snippets.

@dmitryshelomanov
Created February 28, 2019 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmitryshelomanov/4373abb8d77af2b2b30aec21aaf2a12d to your computer and use it in GitHub Desktop.
Save dmitryshelomanov/4373abb8d77af2b2b30aec21aaf2a12d to your computer and use it in GitHub Desktop.
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