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 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.
I used inject, but this seems more compact. Can anyone explain how this works?