Ruby Arrays and Hashes

Came to know about these : Inject method: Say you have an array a1 = [1,2,3,4,5] and you want to sum up the elements, then do this – a1.inject(0) {| sum_so_far, item | sum_so_far + item} This iterates over all the five elements and returns 15. To find the product: a1.injetc(1) { | product, item| […]

Read more "Ruby Arrays and Hashes"