Another function often used with data collections is one which groups the elements according to some evaluation result. Consider the following example. Let's say you have a list of 100 integers and you want to group…
Ruby offers various enumerables on collections that check for validity of the objects within it. Consider the following example:> arr = [1, 2, 3, 4, 5, 6]=> [1, 2, 3, 4, 5, 6]> h = {"a" => 1, "b" => 2, "c" => 3}=> {"a"…
A common scenario that arises when using a collection of any sort, is to get perform a single type of operation with all the elements and collect the result. For example, a sum(array) function might wish to add all the…
Beside simple methods to iterate over objects, Ruby Enumerable provides a number of important higher order constructs that we shall explore in further challenges. One of such important methods is collect method, also…
In the previous challenge, we learned about each method being central to all of the methods provided by Enumerable class. One of such useful methods is each_with_index which allows you to iterate over items along with…
In control structures tutorial, we learned about various methods to iterate over a collection like unless, loop and the most commonly used eachmethod. Ruby, however, provides an Enumerable module which packages a bunch…