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.
oh no!
This is a very compact solution, but this is actually not the best approach. Looking closely at the code this is generating an array for each key witht the default value increasing its space complexity based on the input of n, keys in this case, so if you have 1 million keys, this code creates 1 million array objects before it can be converted into the final hash. Array are complex objects that takes fair amount of space (memory). besides this fact this code is also complex to read for anyone who is not fairly intermediate level or higher in ruby.
One liners are elegant looking code but we have to think of tradeoffs when making such choices.
good solution
I kept getting 'can't connect to server' for this and the bang version. Oh well.
When the task is asking for the two largest numbers in an array, I fail to see how a solution which actually sorts the entire array is a best practice...
This failure solution in this case:
Fair enough, guess I was overthinking
The Kata description explicitely states: "The start time will always be before the end time."
Also AM/PM has nothing to do with this. "Time is stored internally as the number of seconds with fraction since the Epoch, January 1, 1970 00:00 UTC"
I don't think this would work if there were more test cases ._.
First instance of an AM/PM where the start_time >= than the end_time for example
This comment is hidden because it contains spoiler information about the solution
oh dear, and to think it was just this easy all along XD
Didn't know that hashes could be manipulated that way!
I personnaly prefer map/reduce because its how I learned the concept, from big data map/reduce
It never gets added. The way join works is it just joins the elements using the given character, doesn't append after each one.
http://www.ruby-doc.org/core-2.1.2/Array.html#method-i-join
looks good, but I'm not sure I can
read where in the code, the final
comma gets chopped off. Hmmm.
Loading more items...