Git Product home page Git Product logo

ruby-enumerables-cartoon-collections-lab-part-1-sfo01-seng-ft-021521's Introduction

Cartoon Collections - Part 1

Learning Goals

  • Get familiar iterating through arrays with the each Enumerable and its variants

Instructions

There are two methods to complete in this lab:

  1. greet_characters
  2. list_dwarves

Write these methods in cartoon_collections.rb using the details below. Use learn to test your solutions.

Method 1 — greet_characters

Create a method called greet_characters that takes one parameter, an Array of Strings. This method should iterate over this array and use the elements to print out a custom greeting for each.

If we were to pass in the following array, for instance:

characters_array = ["Hoggle", "Ludo", "Sir Didymus"]

greet_characters(characters_array) should output the following:

Hello Hoggle!
Hello Ludo!
Hello Sir Didymus!

Use each to interpolate the elements of the array into a string. Check out the Ruby documentation for additional guidance.

Method 2 — list_dwarves

The list_dwarves method is similar to the greet_characters, but with a slight variation. This method should accept an Array of Strings. The method should interpolate each string and print it out like last time. However, this time, we need to list out the position of each element being printed as well.

For example, if we had the following:

dwarves_array = ["Gimli", "Thorin", "Balin", "Gloin"]

list_dwarves(dwarves_array) should output:

1. Gimli
2. Thorin
3. Balin
4. Gloin

For this, using each won't work. Instead, take a look at the documentation for each_with_index and use the information to help you implement this method.

Hint: The first element of an array is always at an index of 0, but the list above starts with 1 for human readability.

Use learn to check your progress and learn submit to submit your work when finished.

Conclusion

Using each is a good way to get familiar with how Enumerables work. When we're first learning to speak, we might refer to all dogs as dogs, and we'll technically be correct. From there, we might start learning to differentiate - some dogs are retrievers, and others are dachshunds. As mentioned previously, each can be used to complete all sorts of tasks. Now that we have an understanding of it, we can start to learn some of the more expressive alternatives.

Resources

View Cartoon Collections Lab on Learn.co and start learning to code for free.

ruby-enumerables-cartoon-collections-lab-part-1-sfo01-seng-ft-021521's People

Contributors

sarogers avatar kthffmn avatar maxwellbenton avatar arelenglish avatar annjohn avatar deniznida avatar sgharms avatar ga-be avatar dfenjves avatar markedwardmurray avatar sophiedebenedetto avatar vanessadean avatar fislabstest avatar octosteve avatar preetness avatar mjhough avatar kevinmirc avatar bhollan avatar fs-lms-test-bot avatar aspenjames avatar realandrewcohn avatar ahimmelstoss avatar

Watchers

Kaitlin Vignali avatar Mohawk Greene avatar Victoria Thevenot avatar Otha avatar raza jafri avatar  avatar Joe Cardarelli avatar  avatar  avatar Ben Oren avatar Matt avatar Alex Griffith avatar  avatar Amanda D'Avria avatar  avatar Ahmed avatar Nicole Kroese  avatar Dominique De León avatar  avatar Lisa Jiang avatar Vicki Aubin avatar  avatar  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.