Created
November 16, 2021 17:08
-
-
Save Abiola-Farounbi/6d718738dbca3a61d576ae7724e05dd2 to your computer and use it in GitHub Desktop.
Coderbyte Calculator Solution
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 Calculator(str) { | |
var arithmeticOperators = ['+', '-', '/', '*']; | |
var replacedStr = str.replace(/(.)\(/g, function (match, g1) { | |
if (arithmeticOperators.indexOf(g1) != -1) | |
return match; | |
else | |
return match.replace(g1, g1 + '*'); | |
}); | |
return eval(replacedStr); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment