Coder Social home page Coder Social logo

enumerable-methods's Introduction

Enumerable-Methods

The Enumerable module that gets mixed into the Array and Hash classes (among others) and provides lots of handy iterator methods. To prove that there's no magic to it, we are going to rebuild those methods.

Enumerable Methods List

  • Create #my_each, a method that is identical to #each but (obviously) does not use #each. You'll need to remember the yield statement. Make sure it returns the same thing as #each as well.

  • Create #my_each_with_index in the same way.

  • Create #my_select in the same way, though you may use #my_each in your definition (but not #each).

  • Create #my_all? (continue as above)

  • Create #my_any?

  • Create #my_none?

  • Create #my_count

  • Create #my_map

  • Create #my_inject

  • Test your #my_inject by creating a method called #multiply_els which multiplies all the elements of the array together by using #my_inject, e.g. multiply_els([2,4,5]) #=> 40

  • Modify your #my_map method to take a proc instead.

  • Modify your #my_map method to take either a proc or a block. It won't be necessary to apply both a proc and a block in the same #my_map call since you could get the same effect by chaining together one #my_map call with the block and one with the proc. This approach is also clearer, since the user doesn't have to remember whether the proc or block will be run first. So if both a proc and a block are given, only execute the proc.

Live Code

Run on Repl.it

Built With

  • Ruby
  • VS Code

Testing With Rspec.

  • Boot up your terminal and punch in gem install rspec to install RSpec. Once that’s done, you can verify your version of RSpec with rspec --version, which will output the current version of each of the packaged gems. Take a minute also to hit rspec --help and look through the various options available.

  • Finally, cd into a project directory that you wish to configure for use with RSpec and type rspec --init to initialize RSpec within the project. This will generate two files, .rspec and spec/spec_helper.rb

  • To check whether your test are passing or failing, go to your terminal and type rspec.

Author Details

πŸ‘€ Ijay Abby

🀝 Contributing

Contributions, issues and feature requests are always welcome!

I love meeting other developers, especially ones that give me advice on how to improve my work.

Feel free to check the issues page.

Show your support

Finally, if you've read this far, don't forget to give this repo a ⭐️. They're free . . . I think.

Acknowledgments

  • This Project is available on The Odin Project.
  • Thanks to Microverse and all our peers and colleagues there.

πŸ“ License

This project is MIT licensed.

enumerable-methods's People

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

lichapa

enumerable-methods's Issues

team-145-galbas

You should refactor the readme file to add how to run tests

Remove all debuging codes like the p statements which are left from your codes

Edit this Pull Request's name, make it descriptive and meaningful. I mean that it should reflect the work you are implementing on this Pull Request, currently its name is code review => that name doesna't reflect the actual work that you are implementing in it.

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.