Each question in this quiz is timed.
Given the array definition below, which of the following statements does NOT return 'b':
arr = ['a', 'b', 'c', 'd', 'e']
arr[1]
arr.fetch('b')
arr.at(1)
arr.find{|i| i=='b'}
Given the array definition below, which of the following statements raises an exception:
arr.select{|i| i=='b' }.map(&:upcase)
arr.find{|i| i=='b' }.map(&:upcase)
arr.take(2).last(1).map(&:upcase)
arr.sample(3).map(&:upcase)
What is the output from the following:
arr = ['a', 'b', 'c', 'd', 'e'] arr.map(&:upcase).reject!{|i| i=='B' } puts arr
[ A, C, D, E ]
[ B ]
[ a, b, c, d, e]
[ b ]
Which of the following techniques CANNOT be used to create an array composed of four "a" characters, i.e.
[ "a", "a", "a", "a"]
Array.new(4, "a")
["a"]*4
"aaaa".split
Array.new(4){|i| "a" }
Which of the following array comparisons (==) return a true value
["a", 5, "6"]==["a", 5.0, "6"]
["a", nil, 5, "6"].compact==["a", 5, "6", nil].compact
["a", 5, "6"].map(&:to_s)==["a", 5.0, 6].map(&:to_s)
["a", 5, "6"]==["a", 5.0, 6]
["a", 5, "6"]==["a", 5, "6", nil]
Which of the following will result in the string "12345"
(1...5).map(&:to_s).join('')
12345.to_s.split.sum('')
"54321".reverse
"54321".split.reverse.join
Given the array
nums = [8, 13, 27, 61, 50].shuffle
nums.select{|n| n.even? }
nums.find{|n| n.even? }
nums.filter{|n| n.even? }
[nums[0], nums[-1]]
What is the expected output from the following code:
arr = ['a', 'b', 'c', 'd', 'e'] puts ['a', 'e', 'f'] | ['b'] & arr
['a', 'e', 'b']
['a', 'e', 'f', 'b']
['a', 'b', 'c', 'd', 'e', 'f']
['a', 'b', 'c', 'd', 'e']
What is the output after the following sequence of array operations:
foo = ['a', 'b', 'c'] foo << "x" foo.shift foo.append(['d', 'e', 'f']) foo.unshift("y") foo.pop puts foo
['y', 'b', 'c', 'x', 'd', 'e']
['y', 'b', 'c', 'x' ]
['a', 'b', 'c', ['d', 'e', 'f']]
names = [ "Aodhan", "Domhnall", "Caoimhe", "Blaithin"] scores = [ 68, 23, 88, 71 ] puts names.zip(scores).sort_by{|el| el[1] }.last[0]
Aodhan
Domhnall
Caoimhe
Blaithin