Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SaulDoesCode/d9828c08da2cdec92a7385c7392d3cc7 to your computer and use it in GitHub Desktop.
Save SaulDoesCode/d9828c08da2cdec92a7385c7392d3cc7 to your computer and use it in GitHub Desktop.
semi functional experiment with numbers
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