Created
March 6, 2020 05:44
-
-
Save harrisonmalone/222ec5c5577ac9054d3d0fd1eadac4c0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .each drills | |
# 1. The following array will be used in the .each challenges | |
# beatles = ['george harrison', 'ringo starr', 'john lennon', 'paul mccartney'] | |
# a. Using .each print each of the beatles to the screen | |
# b. Using .each print each of the beatles to the screen except for john lennon | |
# c. Using .each print out the message "<the name of the beatle> was a founding member of the band the beatles" | |
# d. Define a hash called beatles, in it have a members key with the value of the array defined above, also have an instruments key with the value of an array which is ['guitar', 'drums', 'bass', 'keyboard'] | |
# e. Using .each_with_index print out the message "<the name of the beatle> was a founding member of the band the beatles, and they played <an instrument>" | |
# f. Using .each print out each of the beatles to the screen... but only their first names | |
# g. Define an array named rock_stars, using .each push each of the beatles into the array rock_stars and then print rock_stars | |
# h. Using .each_with_index loop through the beatles array until you get to john lennon then print "john lennon has an index of <index>" | |
# i. Using .each, if the beatle has a first name longer than 4 letters push their name into an array called beatles_with_long_names, print this array | |
# j. Using .each and .upcase, loop through the array and .upcase all the beatles and push their new upcased name into a new array called upcased_beatles, print upcased_beatles | |
# .map drills | |
# 2. The following array will be used in the first set of .map challenges | |
# numbers = [1, 2, 3, 4] | |
# a. Using .map, add one to each of the items is the numbers array, you should store this new array in a variable called plus_one, when you print plus_one it should be [2, 3, 4, 5] | |
# b. Using .map create the following array [10, 20, 30, 40], you should store this new array in a variable called times_ten | |
# c. Using .map create the following array [0, 1, 2, 3], you should store this new array in a variable called minus_one | |
# d. Using .map transform each item in the array so that it now contains the string "<number> is an item in the array" | |
# e. Using .map if the number is less than 3 return nil otherwise keep the original number | |
# 3. The following array will be used the second set of .map challenges | |
# text = ["Lorem ipsum, dolor sit amet consectetur adipisicing elit.", "Distinctio optio velit officia vel, impedit at suscipit unde.", "Nam pariatur numquam rerum. Suscipit ut earum, harum fugiat dolor amet et explicabo!"] | |
# a. Using .map wrap every item in the text array in <p> tags (opening and closing) | |
# b. Using .map override every item in the array so that it just contains 3 strings being "Coder Academy" | |
# c. Using .map return the number of words that are contained in each string in the array, you should end up with [8, 9, 13] | |
# .select drills | |
# 4. The following array will be used in the first set of .select challenges | |
# numbers = [100, 276, 4, 87] | |
# a. Using .select, return an array with only numbers greater than 50 | |
# b. Using .select, return an array with only numbers less than or equal to 100 | |
# c. Using .select, return an array with only numbers == to 4 | |
# 5. The following array will be used in the second set of .select challenges | |
# shoes = [ | |
# { | |
# brand: 'nike', | |
# name: 'air zoom structure' | |
# }, | |
# { | |
# brand: 'adidas', | |
# name: 'ultraboost' | |
# }, | |
# { | |
# brand: 'nike', | |
# name: 'air zoom pegasus' | |
# }, | |
# { | |
# brand: 'asics', | |
# name: 'gel nimbus' | |
# }, | |
# { | |
# brand: 'asics', | |
# name: 'kayano' | |
# }, | |
# { | |
# brand: 'adidas', | |
# name: 'pureboost go' | |
# }, | |
# { | |
# brand: 'nike', | |
# name: 'epic react' | |
# }, | |
# { | |
# brand: 'nike', | |
# name: 'joyride run' | |
# } | |
# ] | |
# a. Using .select, return an array of hashes that have the brand nike | |
# b. Using .select, return an array of hashes that have the brand adidas | |
# c. Using .select, return an array of hashes that have the brand nike or asics | |
# .find drills | |
# 6. The following array will be used in the second set of .find challenges | |
# numbers = [987, 43, 299, 101] | |
# a. Using .find, return the first item from the array that's less than 200 | |
# b. Using .find, return the first item from the array that's greater than 200 but less than 300 | |
# 7. The following array will be used in the second set of .find challenges | |
# football_teams = [ | |
# { | |
# name: 'Collingwood', | |
# founded: '1892', | |
# ground: 'MCG' | |
# }, | |
# { | |
# name: 'Essendon', | |
# founded: '1872', | |
# ground: 'Marvel Stadium' | |
# }, | |
# { | |
# name: 'Melbourne', | |
# founded: '1858' | |
# ground: 'MCG' | |
# }, | |
# { | |
# name: 'St Kilda', | |
# founded: '1873', | |
# ground: 'Marvel Stadium' | |
# }, | |
# { | |
# name: 'North Melbourne' | |
# founded: '1869', | |
# ground: 'Marvel Stadium' | |
# }, | |
# { | |
# name: 'Footscray', | |
# founded: '1883', | |
# ground: 'Marvel Stadium' | |
# }, | |
# { | |
# name: 'Hawthorn', | |
# founded: '1902', | |
# ground: 'MCG' | |
# }, | |
# { | |
# name: 'Richmond' | |
# founded: '1885', | |
# ground: 'MCG' | |
# }, | |
# { | |
# name: 'Carlton', | |
# founded: '1864', | |
# ground: 'Marvel Stadium' | |
# }, | |
# { | |
# name: 'Geelong', | |
# founded: '1859', | |
# ground: 'GMHBA Stadium' | |
# } | |
# ] | |
# a. Using .find, return the first item from the array of hashes that has a founding year of 1873 | |
# b. Using .find, return the first item from the array of hashes that has a name starting with 'C' | |
# c. Using .find, return the first item from the array of hashes that has the ground 'GMHBA Stadium' | |
# d. Using .select, return the items that have the ground 'MCG', then on that filtered array use the .find method to selecr the first team that was founded before 1860 | |
# binding.pry drills | |
# require 'pry' | |
# To use pry: | |
# 1. > gem install pry (we've all already done that!) | |
# 2. Uncomment line 183 (require 'pry') | |
# 8. Follow the instructions | |
# a. Uncomment the while loop code below | |
# counter = 0 | |
# while counter < 10 | |
# puts "hello" | |
# binding.pry | |
# counter += 1 | |
# end | |
# b. Execute the code | |
# > ruby 01-26-each-map-select-find-pry.rb | |
# c. Notice that the code stops at the binding.pry, this is our breakpoint, type the word counter into terminal and see what value is returned | |
# d. Now type continue and notice that the code stops again | |
# e. Repeat steps c and d 5 times, notice what counter is returning | |
# f. Type exit! to get out of the binding.pry loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment