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.
beautiful - but slow...
Very readable 👍
My solution looks like yours. Is yours really faster than @levivoelz?
Hey @clayton.enga, your test case is invalid because on Bob's IQ test he will only be given an array of numbers with ONE different number than the rest in terms of 'evenness'.
Come on guys, this is inefficient as hell.
I tried your implementation with this input:
iq_test('1 2 3 4')
The result:
=> 1
This seems incorrect because 1 is not different from all the others. It should probably return
nil
orfalse
or raise an exception in this case. This comment applies to many of the other solutions as well.But maybe it's fair to assume from the problem description that the IQ test will never give such a question...?
Great solution.......i liked it.
more on we can use collect rather use map second time like:
nums = numbers.split.map(&:to_i).collect {|x| x.even?}
Thanks you....!!
One map for sure. Not sure why I did that. Thanks for pointing it out!
Nice and clean way !
However i got a question (i'm relatively new to ruby) :
Performance wise, what's the better between :
.map{|n| n.to_i.even? }
And
.map(&:to_i).map(&:even?)
Thanks
Such a nice and elegent solution. I always have this inkling that my code can be much cleaner. Well done.