Created
August 24, 2021 12:31
-
-
Save kermit-klein/8525142fb1b96a490644f3585803ede2 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
function calculate(obj) { | |
switch (obj.type) { | |
case "number": | |
return parseInt(obj.value); | |
case "+": | |
return calculate(obj.left) + calculate(obj.right); | |
case "-": | |
return calculate(obj.left) - calculate(obj.right); | |
case "*": | |
return calculate(obj.left) * calculate(obj.right); | |
case "/": | |
return calculate(obj.left) / calculate(obj.right); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment