Giter VIP home page Giter VIP logo

map-method-rewrite's Introduction

Code Climate Test Coverage Dependency Status Build Status

#Description Post course practice. Re-writing ruby's map method.

#Challenge

  1. Reopen the Array class or subclass it.
  2. 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.
  3. 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.
  4. 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

  1. To understand how the map method works

#How to use

  1. Clone the repo
  2. Load the array.rb file in irb using the command: require './lib/array.rb'
  3. Create a new array of objects
  4. Call the mymap method on the array as you would the map method
  5. To use the recursive method, call mymap_recursive on the array as you would the map or pinject methods

#How to test

  1. Run 'bundle install'
  2. Run 'bundle exec rspec'

#What I learned

  1. What &method and &block does
  2. What the to_proc method does
  3. How the map method does its magic
  4. Recursion

map-method-rewrite's People

Contributors

zshnr avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.