Last active
April 12, 2019 09:22
-
-
Save Belrestro/0f30922206ccace130c0 to your computer and use it in GitHub Desktop.
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 simMath = { | |
memo:{}, | |
operation:function(array, method){ | |
return Array.prototype.join.call(array, method); | |
}, | |
calculate:function(array, method){ | |
return Array.prototype.reduce.call(array, method); | |
}, | |
plus: function(){ | |
var operation = this.operation(arguments, '+'); | |
if(operation in this.memo) | |
return this.memo[operation]; | |
var result = this.calculate(arguments, function(a,b){return a+b}); | |
this.memo[operation] = Number(result); | |
return result; | |
}, | |
minus: function(){ | |
var operation = this.operation(arguments, '-'); | |
if(operation in this.memo) | |
return this.memo[operation]; | |
var result = this.calculate(arguments, function(a,b){return a-b}); | |
this.memo[operation] = Number(result); | |
return result; | |
}, | |
multiply: function(){ | |
var operation = this.operation(arguments, '*'); | |
if(operation in this.memo) | |
return this.memo[operation]; | |
var result = this.calculate(arguments, function(a,b){return a*b}); | |
this.memo[operation] = Number(result); | |
return result; | |
}, | |
devide: function(){ | |
var operation = this.operation(arguments, '/'); | |
if(operation in this.memo) | |
return this.memo[operation]; | |
var result = this.calculate(arguments, function(a,b){return a/b}); | |
this.memo[operation] = Number(result); | |
return result; | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment