Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This calculator does not support expressions like "1 * (1 + 1)", as stated in the task description:
"Create a simple calculator that given a string of operators (), +, -, *, / and numbers separated by spaces returns the value of that expression"
this solution is not correct,
it is just fitting for tests,
it does not work for the example from the condition
Test.assert_equals(calc.evaluate("2 / 2 + 3 * 4 – 6"), 7)
not converting the numbers to floats before applying the operator?
The idea is amazing, I love it very much. but the code itself is a little weak. For example :("-3 - 1 * 2 + 2 - 7") have different result with ("-3 -1 * 2 + 2 - 7"). one purpose, two result.
This comment is hidden because it contains spoiler information about the solution
Can anyone explain what this statement is doing? return string.split(op).map { |s| evaluate(s) }.inject(op.strip) It looks like recursion if I'm correct. Thanks!
Really clever solution!
Seems, your solution doesn't support float numbers
I agree with Ibriais, but still, this is a pretty clever solution :).
How are you getting an expected result of -3 from this?
The result should be -3.66666666... which this solution does evaluate to correctly.
doesn't seem to work for all the expressions?
try this:
3 - 3 * 8 / 3 / 3 - 4
Expected: -3, Actual: -1
Best solution so far ;)