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.
A more elegant request would be to allow unlimited chaining of calculations. The result could be obtained by implementing
to_s
andto_f
. E.g.puts Calc.new.one.plus.two.times.three # 9.0
Ruby, test suite lacks :
-testing for implementing zero
-random tests
The final tests dont catch it if you forget to implement zero.
This one was a lot of fun! I enjoyed seeing all the different approaches in the solutions.
Mine's pretty straightforward as well. Reduce takes operators as symbols, which is incredibly useful in this case.
I found it unclear that this only had to be built to handle exactly 3 chained methods, not an arbitrary amount. So for anyone wondering, you only need it to work for Calc.new.number.operator.number. Nothing else.
It looks like you're returning a method instead of a number. Maybe ensure you're returning a number?
The most interesting solution. Mine is also not using eval, but quite simple and easy to read. @JoshBrodieNZ your solution is universal, man, you could use it for half of katas with minor changes ;)
My code work fine in my local machine but when tryingto submit the test always return the same
I don't know if the is something wrong with the test. Could someone take a look.
This comment is hidden because it contains spoiler information about the solution
I also hate eval and haven't ever used curry, but I will now!
This comment is hidden because it contains spoiler information about the solution
think about the different ways each method should respond based on the state of the class. Since we know the calc should execute once given three inputs...you can setup your methods to behave differently
I have never seen curry, setobj, and calling super with a lamba is pretty crazy too...
This comment is hidden because it contains spoiler information about the solution
Loading more items...