Created
February 11, 2019 19:19
-
-
Save gulbanana/e41762cc2c74a5efa6ac3409ccdc8f6f 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
/*******************************/ | |
/* approach 1: structured data */ | |
/*******************************/ | |
function calc(state, x) { | |
return calcSubPart(state, x-1) + calcSubPart(state, x-1); | |
} | |
function calcSubPart(state, y) { | |
return state * y; | |
} | |
function test() { | |
let state = { factor: 2 }; | |
let result = calc(state, 1); | |
} | |
/*******************/ | |
/* approach 2: oop */ | |
/*******************/ | |
class factorCalc { | |
constructor(factor) { | |
this.factor = factor; | |
} | |
function calc(x) { | |
return calcSubPart(x-1) + calcSubPart(x-1); | |
} | |
function calcSubPart(y) { | |
return factor * y; | |
} | |
} | |
function test() { | |
let calculator = new FactorCalc(2); | |
let result = calculator.calc(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment