loading...

Discussion on: Daily Challenge #10 - Calculator

Collapse
mkrl profile image
Mikhail Korolev

Alright, I'm gonna be the one who posts this.

const calc = exp => eval(exp)
Collapse
alvaromontoro profile image
Alvaro Montoro

If you add a check to verify the string is well formed, this will probably be the best and simplest answer.

Collapse
yzhernand profile image
Yozen Hernandez

Similarly unfair, the solution in R:

calc <- function (expr) {
    eval(parse(text=expr))
}
> calc("2 / 2 + 3 * 4 - 6")
[1] 7

Warning: don't do this.