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.
That is more readable than no spaces.
Warning personal preference ahead! Your lack of whitespace makes your solution hard to read.
Poorly worded explanation. There are many grammatical errors.
I love codewars! It's a great site. I'd like to focus on voting on solutions. Right now we have two upvoting options "Best Practice" and "Clever". I feel these categories miss a very important aspect of solving algorithms -- time and space complexity.
Many solutions with poor time or space compexity are often voted up because they are one-liners. If an algorithm can be solved in 1 line but have
O(n)
space complexitiy (eg allocating an n-sized array) vs 2 lines and haveO(1)
space complexity (eg a single counter variable), then the 2 line solution should be voted to the top.We could use the existing voting options to vote-up algorithms with better time or space complexity. But maybe this is an opportunity to reconsider what we care about in regards to solving algorithms.
Do we care if a solution is "Clever" or more vaguely a "Best Practice"? Or do we care about code readablity, time complexity and space complexity?
Also we can put actual numbers on the complexities, instead of voting we can rate an algorithm with it's Big O notation.
O(1), O(n), O(n^2), .. etc
Excellent regexp.
Nice one-liner. The Array allocated by
split('')
orchars
gives this algorithmO(n)
space complexity, it's possible to solve this withO(1)
space complexity. All voted on solutions share this problem.+1 For the only solution which doesn't allocate an array.
Unlike other solutions this has
O(n)
time complexity with a cost ofO(1)
space complexity. Should be upvoted aboveO(n^2)
solutions.Nice one liner! This takes
O(n^2)
can you do it inO(n)
time?Excellent one-liner. This algorithm can be sovled with
O(n)
time complexity. Your solution takes takesO(n*log(n))
(due to the sort).Your use of the destructive
sort!
vssort
will break the chain of method calls.Great one-liner. This solution has a space complexity of O(n) because an array is allocated. In place sorting solutions can have a space completity of O(1).
I think this solution is the simpler than the one-line map solutions. Marking as best practice.
I like this one-line solution. I find this olution clever, but not a best practice.