[Collaborative project]
In this project, we are implementing our custom enumerable methods of Ruby.
Covered methods
- #my_each
- #my_each_with_index
- #my_select
- #my_all?
- #my_any?
- #my_none?
- #my_count
- #my_map
- #my_inject
- #multiply_els which multiplies all the elements of the array together by using #my_inject, e.g. multiply_els([2,4,5]) #=> 40
- Ruby
Clone
https://github.com/Leon-Mbegera/Enumerables
To get a local copy up and running, follow these simple example steps.
- Open a terminal window and enter
clone https://github.com/Leon-Mbegera/Enumerables
- Run git checkout
-b your-branch-name
. Make your contributions - Type in terminal
ruby enumerables.rb
to start testing - Push your branch up to your forked repository
- Open a Pull Request if you want to merge branches with a detailed description of the development branch of the original project for a review
Ruby installed localy
- In your terminal, run
bundle install
to download and install the testing framework" - Type
bundle exec rspec
to run the test cases already written
[1,2,3,4,5,6].my_each{|i| p i}
=> 123456
[3,5,8,1].my_each_with_index{|element, i| p "#{element}: #{i}"}
=> "3 0"
"5 1"
"8 2"
"1 3"
[1,2,3,4,5,6].my_select(&:odd?)
=> [1,3,5]
[1,2,3,4,5,6].my_all?(&:even?)
=> false
[1,2,3,4,5,6].my_any?(&:odd?)
=> true
[1,2,3,4,5,6].my_none?(&:odd?)
=> true
[1,2,3].my_count
=> 3
[1,2,3].my_count { |x| x > 1}
=> 2
[1,5].my_map { |x| x * 2 }
=> [2, 10]
[1,2,3,4,5].my_map Proc.new { |x| x * 4 }
=> [4,8,12,16,20]
(5..10).my_inject(:+)
=> 45
(5..10).my_inject { |sum, n| sum + n }
=> 45
[1,2,4,5,6].my_multiply_els
=> 240
👤 Shoira Toshpulatova
- GitHub: @githubhandle
- LinkedIn: LinkedIn
👤 Leon
- GitHub: @githubhandle
- LinkedIn: LinkedIn
- Thanks to my coding partner and the team
- Inspiration