Enumerable is a collection of iteration method, a Ruby module and a great part of what makes ruby a great programming language. In this project, we try to customize some of the Ruby enumerable functions.
- Clone this Repo
- Navigate to project Directory
- Now, to test each function go to the end of the page and do the following.
- For my_each
[1, 2, 3, 5].my_each { |x| p x }
- Output
=> 1
=> 2
=> 3
=> 5
- For my_each_with_index
[1, 2, 3, 5].my_each_with_index { |x, y| puts "#{x} at #{y}" }
- Output
=> 1 at 0
=> 2 at 1
=> 3 at 2
=> 5 at 3
- For my_select
[1, 2, 3, 4].my_select { |x| x % 2 == 0}
- Output
=> [2, 4]
- For my_all
['alpha', 'apple', 'allen key'].my_all?{ |x| x[0] == 'a' }
- Output
=> true
- For my_any
['alpha', 'apple', 'allen key'].my_any?{ |x| x[-1] == 'y' }
- Output
=> true
- For my_none
['Alpha', 'Apple', 'Allen key'].my_none?{ |x| x[0] == 'z' }
- Output
=> true
- For my_count
arr = [1, 2, 3, 4]
arr.my_count { |i| i%2==0}
- Output
=> 2
- For my_map
[1,2,3,4,4,7,7,7,9].my_map { |i| i*4 }
- Output
=> [4, 8, 12, 16, 16, 28, 28, 28, 36]
- For my_inject
[1,2,3,4,4,7,7,7,9].my_inject(0){|running_total, item| running_total + item }
- Output
=> 44
- Ruby
๐ค Rukundo Eric
- GitHub: @rukundoeric
- Twitter: @rukundoeric005
- LinkedIn: Rukundo Eric
๐ค Sinan Sevgi
- GitHub: @sinansevgi
- LinkedIn: @sinansevgi
Contributions, issues, and feature requests are welcome!
Give a โญ๏ธ if you like this project!
- We would like to thank our code reviewer and anyone else who participated in making this done.
This project is MIT licensed.