Skip to content

Instantly share code, notes, and snippets.

@steadweb
Forked from mattmarcello/gist:ee2ffa06a081ff878fa7
Last active August 29, 2015 14:07
Show Gist options
  • Save steadweb/7e41d535526687e44dfb to your computer and use it in GitHub Desktop.
Save steadweb/7e41d535526687e44dfb to your computer and use it in GitHub Desktop.

What do you know about Comparators and Booleans?

#####(1) Given the following array of integers, for each number, print the numbers less than the number in question. For example, given this array:

nums = [1,2,3]

We should see this output:

1 is greater than no numbers in this set.
2 is greater than 1.
3 is greater than 1, 2.

Use this array:

nums = [
  2, 89, 47, 53, 149, 139, 7, 73, 31, 101, 83, 103, 113, 37, 5,
  13, 23, 17, 61, 29, 71, 3, 43, 67, 19, 131, 11, 59, 107, 109,
  127, 79, 151, 137, 97, 41
]
# your code here

#####(2) Write a method that takes two arguments, a String and a Fixnum. It should return true if that word's length is greater than or equal to the Fixnum. False, if otherwise.

# your code here

#####(3) Select the names in this array where the first letter of the first name is the same as the first letter of the last name OR the last letter of the first name is equal to the last letter of the last name. Use Array.select

names = [
  'Matt Marcello',
  'Andrew Madden',
  'Aldric Giacomoni',
  'PJ Hughes',
  'Jeff Konowitch',
  'Neel Patel'
]
# your code here

#####(3.5) Select the names in the above array where the first letter of the name is NOT equal to the first letter of the last name.

# your code here

#####(4)

Reject restaurants in this array where the michelin rating is less than or equal to 2. Use Array.reject.

restaurants  = [
  { name: 'Spotted Pig', michelin: 1 },
  { name: 'Momofuku Ko', michelin: 2 },
  { name: 'Peter Luger', michelin: 1 },
  { name: 'atera', michelin: 2 },
  { name: 'Jungsik', michelin: 2 },
  { name: 'Gramercy Tavern', michelin: 1 },  
  { name: 'Le Bernardin', michelin: 3 },
  { name: 'Jean Georges', michelin: 3 },
  { name: 'Soto', michelin: 2 },
  { name: 'Daniel', michelin: 3 },
  { name: 'Minetta Tavern', michelin: 1 },
  { name: 'Del Posto', michelin: 1 },
  { name: 'Per Se', michelin: 3 }
]
# your code here

#####(5) Return an array that represents the subset of keys for which the corresponding value is true.

hash = {
  the: true,
  secretary: false,
  strawberry: false,
  walrus: true,
  was: false,
  epistemological: false,
  is: true,
  simon: false,
  garfunkel: false,
  paul: true
}

# your code here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment