Giter Site home page Giter Site logo

phase-3-enumerables-lab's Introduction

require 'pry'

this method returns an array of hashes, which we'll use in the other methods

def spicy_foods [ { name: 'Green Curry', cuisine: 'Thai', heat_level: 9 }, { name: 'Buffalo Wings', cuisine: 'American', heat_level: 3 }, { name: 'Mapo Tofu', cuisine: 'Sichuan', heat_level: 6 } ] end

given an array of spicy foods, return an array of strings

with the names of each spicy food

def get_names(spicy_foods) spicy_foods.map do |food| food[:name] end end

given an array of spicy foods, return an array of hashes

where the heat level of the food is greater than 5

def spiciest_foods(spicy_foods) spicy_foods.filter do |food| food[:heat_level] > 5 end end

given an array of spicy foods and a string representing a cuisine, return a single hash

for the spicy food whose cuisine matches the cuisine being passed to the method

def get_spicy_food_by_cuisine(spicy_foods, cuisine) spicy_foods.find do |food| food[:cuisine] == cuisine end end

given an array of spicy foods, output to the terminal

each spicy food in the following format:

Buffalo Wings (American) | Heat Level: 🌢🌢🌢

HINT: you can use * with a string to produce the correct number of 🌢 emoji.

"hello" * 3 == "hellohellohello"

def print_spicy_foods(spicy_foods) spicy_foods.each do |food| puts "#{food[:name]} (#{food[:cuisine]}) | Heat Level: #{'🌢' * food[:heat_level]}" end end

Given an array of spicy foods, return an array of hashes

sorted by heat level from lowest to highest

def sort_by_heat(spicy_foods) spicy_foods.sort_by do |food| food[:heat_level] end end

given an array of spicy foods, output to the terminal ONLY

the spicy foods that have a heat level greater than 5, in the following format:

Buffalo Wings (American) | Heat Level: 🌢🌢🌢

HINT: Try to use methods you've already written to solve this!

def print_spiciest_foods(spicy_foods) spiciest = spiciest_foods(spicy_foods) print_spicy_foods(spiciest) end

given an array of spicy foods, return an integer representing

the average heat level of all the spicy foods in the array

def average_heat_level(spicy_foods) total_heat_level = 0 spicy_foods.each do |food| total_heat_level += food[:heat_level] end total_heat_level / spicy_foods.length end

alternate solution using sum

def average_heat_level(spicy_foods)

total_heat_level = spicy_foods.sum do|food|

food[:heat_level]

end

total_heat_level / spicy_foods.length

end

phase-3-enumerables-lab's People

Contributors

byrne22 avatar ihollander 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.