- Ruby
- Linters
First ensure that you have ruby installed on your local machine. To get a local copy up and running follow these simple example steps.
Ruby installed on your local machine. Code editor (like VSCode) Terminal or similar to execute the program.
Download a copy of the enumerables.rb file
Place the file on the same folder as your project and include it on your script Use the different methods like so
testarray.my_each { |x| puts "The number is #{x}" }
Returns every item of your array
testarray.my_each_with_index { |val,index| puts "index: #{index} for #{val}" }
Returns every item of your array along with the index
testarray.my_select { |n| n.even? }
Returns every item of the array that matches your query
puts testarray.my_all { |n| n < 20 }
Returns true if all the elements of your array match the query
puts testarray.my_none { |n| n < 20 }
Returns true if all the elements of your array don't match the query
puts testarray.my_any { |n| n == 20 }
Returns true if at least one element of the array matches the query
puts testarray.my_count { |n| n.even? }
Returns the number of elements in your array that match the query
square = Proc.new { |x| x**2 }
puts testarray.my_map { |x| x**2 }
puts testarray.my_map(square)
Can be used with a block or a proc (prioritizes the proc). Return the modified elements according to the query
puts testarray.my_inject { |sum, n| sum * n }
Returns the sum of all the elements according to the query
puts multiply_els([2,4,5])
This method uses my_map to multiply the elements of an array with a sum
👤 Sergio Cortes Satizabal
- GitHub: @githubhandle
- Twitter: @twitterhandle
👤 Gregorio Rábago Sainz
- GitHub: @githubhandle
- Twitter: @twitterhandle
Contributions, issues, and feature requests are welcome!
Feel free to check the issues page.
Give a ⭐️ if you like this project!
- Hat tip to anyone whose code was used
- Inspiration
- etc
This project is MIT licensed.