Git Product home page Git Product logo

phase-3-cartoon-collections's Introduction

Enumerables: Cartoon Collections Lab

Learning Goals

  • Get familiar iterating through arrays with enumerator methods like #map, #find, and #include?.
  • Build methods and control their return values.
  • Practice control flow with if and else statements.

Instructions

Complete the following methods in cartoon_collections.rb.

#roll_call_dwarves

dwarves

This method should accept an array of dwarf names, for instance:

["Doc", "Dopey", "Bashful", "Grumpy"]

It should then print out each name, in number order, using puts. The print-out should look like this:

1. Doc
2. Dopey
3. Bashful
4. Grumpy

Look into the #with_index method to access the index for each element as you are iterating.

#summon_captain_planet

captain-planet

This method should accept an array argument of planeteer calls that will look like this:

planeteer_calls = ["earth", "wind", "fire", "water", "heart"]

It should then capitalize each element and add an exclamation point at the end. The return value of this method should be an array, in this example:

summon_captain_planet(planeteer_calls)
# => ["Earth!", "Wind!", "Fire!", "Water!", "Heart!"]

The #map method might be appropriate for this task, take a look at it here.

Once the test for this method is passing, move on to the next method, long planeteer calls.

#long_planeteer_calls

The #long_planeteer_calls method should accept an array of calls. The method should return true if any of the calls are longer than four characters. For example:

short_words = ["puff", "go", "two"]
long_planeteer_calls(short_words)
#=> false

assorted_words = ["two", "go", "industrious", "bop"]
long_planeteer_calls(assorted_words)
#=> true

Notice the return value of this method is either true or false, depending on the array it was given as an argument.

Checkout the Ruby docs on arrays for a hint.

#find_the_cheese

dancing-mice

The #find_the_cheese method should accept an array of strings. It should then look through these strings to find and return the first string that is a type of cheese. The types of cheese that appear are "cheddar", "gouda", and "camembert".

For example:

snacks = ["crackers", "gouda", "thyme"]
find_the_cheese(snacks)
# => "gouda"

soup = ["tomato soup", "cheddar", "oyster crackers", "gouda"]
find_the_cheese(soup)
# => "cheddar"

If, sadly, a list of ingredients does not include cheese, return nil:

ingredients = ["garlic", "rosemary", "bread"]
find_the_cheese(ingredients)
# => nil

You can assume that all strings will be lowercase. Take a look at the #include? method for a hint. This method asks you to return a string value instead of printing it so keep that in mind.

Resources

phase-3-cartoon-collections's People

Contributors

sarogers avatar kthffmn avatar arelenglish avatar annjohn avatar maxwellbenton avatar deniznida avatar sgharms avatar ga-be avatar ihollander avatar sophiedebenedetto avatar markedwardmurray avatar lizbur10 avatar dfenjves avatar vanessadean avatar tmtarpinian avatar fislabstest avatar octosteve avatar preetness avatar mjhough avatar kevinmirc avatar drakeltheryuujin avatar bhollan avatar fs-lms-test-bot avatar aspenjames avatar realandrewcohn avatar ahimmelstoss 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.