Skip to content

Instantly share code, notes, and snippets.

@nenodias
Created August 27, 2022 20:47
Show Gist options
  • Save nenodias/1c594eeff7f1476b7c27526e85d0a836 to your computer and use it in GitHub Desktop.
Save nenodias/1c594eeff7f1476b7c27526e85d0a836 to your computer and use it in GitHub Desktop.
Functional Javascript
const zero = (fn) => {
if(fn !== undefined){
return fn(0)
}
return 0
}
const one = (fn) => {
if(fn !== undefined){
return fn(1)
}
return 1
}
const two = (fn) => {
if(fn !== undefined){
return fn(2)
}
return 2
}
const three = (fn) => {
if(fn !== undefined){
return fn(3)
}
return 3
}
const four = (fn) => {
if(fn !== undefined){
return fn(4)
}
return 4
}
const five = (fn) => {
if(fn !== undefined){
return fn(5)
}
return 5
}
const six = (fn) => {
if(fn !== undefined){
return fn(6)
}
return 6
}
const seven = (fn) => {
if(fn !== undefined){
return fn(7)
}
return 7
}
const eight = (fn) => {
if(fn !== undefined){
return fn(8)
}
return 8
}
const nine = (fn) => {
if(fn !== undefined){
return fn(9)
}
return 9
}
const plus = (a) => {
return (b) => b + a
}
const minus = (a) => {
return (b) => b - a
}
const times = (a) => {
return (b) => b * a
}
const dividedBy = (a) => {
return (b) => Math.floor(b / a)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment