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 comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Then it won't work, but the instructions say:
Create a five_num method that takes an array of integers as an argument
so checking for invalid input is not a requirement.
This comment is hidden because it contains spoiler information about the solution
Thanks for the tip. I think the Kata description has changed since I wrote my solution.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
The de-facto community style guide for Ruby suggests using parens if the method accepts paramters and leaving off the parens if the method takes no parameters.
Assignment in Ruby (and in most other programming languages) works right to left, so the result of the expression on the right of the
=
is stored in the variable or variables on the left.https://www.oreilly.com/library/view/the-ruby-programming/9780596516178/ch04s05.html
https://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Operators#Assignment
This comment is hidden because it contains spoiler information about the solution
Huh, I never noticed that when writing the solution!
Looks like the Kata needs more tests.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
grep returns an Array of every element that matches the pattern.
matches = arr.grep(/.*foo.*/)
is the equivalent ofmatches = arr.select { |e| /.*foo.*/ === e }
The pattern in my solution is looking for any word in the
dictionary
that starts with theinput
string, ignoring case.lazy returns a lazy enumerator, which when used with methods like
grep
,map
, etc. will only enumerate values as they are needed.When
first(5)
is called it forces the lazy enumeration to be evaluated and will only search through the dictionary until it finds 5 matching items.Without the
lazy
,grep
would search through the entire dictionary for matches which would be wasteful when only the first 5 are required.Loading more items...