#Description Post course practice. Re-writing ruby's map method.
#Challenge
- Reopen the Array class or subclass it.
- Write a unit test for the map() method, then reopen the Array class and implement it. You will need to use the yield keyword to call the block passed to map(). Don't forget that map() returns a new array, instead of modifying the array it's called on.
- Name your method differently (that is, not map() or subclass Array) because rspec uses map() internally, so the tests will fail with weird messages unless your implementation of map is perfect.
- If you'd like a harder challenge, implement the map() method without iterations, using recursion. You'll need a recursive helper function that will need to have a different signature than normal map(). Don't forget that you may need to operate on a copy of the original array. Think about the base case when the recursion should stop. If you do this, the teachers will be seriously impressed because this is hard, even though you can write the solution in only two lines of code.
#Learning Objective
- To understand how the map method works
#How to use
- Clone the repo
- Load the array.rb file in irb using the command: require './lib/array.rb'
- Create a new array of objects
- Call the mymap method on the array as you would the map method
- To use the recursive method, call mymap_recursive on the array as you would the map or pinject methods
#How to test
- Run 'bundle install'
- Run 'bundle exec rspec'
#What I learned
- What &method and &block does
- What the to_proc method does
- How the map method does its magic
- Recursion