Skip to content

Instantly share code, notes, and snippets.

@Abiola-Farounbi
Created November 16, 2021 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Abiola-Farounbi/6d718738dbca3a61d576ae7724e05dd2 to your computer and use it in GitHub Desktop.
Save Abiola-Farounbi/6d718738dbca3a61d576ae7724e05dd2 to your computer and use it in GitHub Desktop.
Coderbyte Calculator Solution
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