Created
July 14, 2016 19:33
-
-
Save SaulDoesCode/d9828c08da2cdec92a7385c7392d3cc7 to your computer and use it in GitHub Desktop.
semi functional experiment with numbers
This file contains 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
var plus = (a, b) => a + b; | |
var minus = (a, b) => a - b; | |
var divide = (a,b) => a / b; | |
var multiply = (a,b) => a * b; | |
var num = a => ({ | |
add(b) { | |
a = plus(a, b); | |
return this; | |
}, | |
minus(b) { | |
a = minus(a, b); | |
return this; | |
}, | |
multiply(b) { | |
a = multiply(a,b); | |
return this; | |
}, | |
divide(b) { | |
a = divide(a,b); | |
return this; | |
}, | |
increase(...nums) { | |
a = nums.reduce(plus, a); | |
return this; | |
}, | |
decrease(...nums) { | |
a = nums.reduce(minus, a); | |
return this; | |
}, | |
print() { | |
console.log(a); | |
return this; | |
}, | |
get() { | |
return a; | |
}, | |
set(b) { | |
a = b; | |
return this; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment