[Collaborative project]
In this project, we are implementing our version of Ruby's enumerable methods.
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
git clone git@github.com:marijanbrvar/Enumerables.git
To get a local copy up and running, follow these simple example steps.
- Open a terminal window and enter
fit clone https://github.com/marijanbrvar/BubbleSort.git
- Make your new cloned directory your active directory
- Currently, you are in the "development branch."
- Change your current branch to enumerables branch
git checkout enumerables
- Use
irb
to test folder with following console commandirb -I . -r enumerable.rb
- Once you are in the irb console, use the syntax to invoke the method stated below
Ruby installed localy
Use IRB to test the code
[1,2,3,4,5,6].my_select(&:even?)
=> [2,4,6]
[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
👤 Marijan Brvar
- GitHub: @githubhandle
- Twitter: @twitterhandle
- LinkedIn: LinkedIn
👤 Tanzila
- GitHub: @githubhandle
- Twitter: @twitterhandle
- LinkedIn: LinkedIn
This project is MIT licensed.