0
0
Rubyprogramming~10 mins

Zip for combining arrays in Ruby - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to combine two arrays element-wise using zip.

Ruby
a = [1, 2, 3]
b = [4, 5, 6]
combined = a.[1](b)
puts combined.inspect
Drag options to blanks, or click blank then click option'
Amap
Bzip
Ceach
Dselect
Attempts:
3 left
💡 Hint
Common Mistakes
Using map instead of zip will not pair elements from both arrays.
2fill in blank
medium

Complete the code to print the first pair from the zipped arrays.

Ruby
a = ['a', 'b', 'c']
b = [1, 2, 3]
zipped = a.zip(b)
puts zipped[[1]].inspect
Drag options to blanks, or click blank then click option'
A-1
B1
C2
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 as index will give the second pair, not the first.
3fill in blank
hard

Fix the error in the code to correctly zip arrays and print the result.

Ruby
x = [10, 20]
y = [30, 40]
result = x.[1](y)
puts result.inspect
Drag options to blanks, or click blank then click option'
Azip!
Bzip()
Czip
Dziped
Attempts:
3 left
💡 Hint
Common Mistakes
Adding parentheses or exclamation mark causes errors.
4fill in blank
hard

Fill both blanks to create a hash from two arrays using zip and to_h.

Ruby
keys = [:name, :age, :city]
values = ['Alice', 30, 'NYC']
hash = keys.[1](values).[2]
puts hash.inspect
Drag options to blanks, or click blank then click option'
Azip
Bto_h
Cmap
Dflatten
Attempts:
3 left
💡 Hint
Common Mistakes
Using map instead of zip or missing to_h conversion.
5fill in blank
hard

Fill all three blanks to zip three arrays and print the combined array.

Ruby
a = [1, 2]
b = ['x', 'y']
c = [:alpha, :beta]
combined = a.[1](b).[2] { |pair| pair.[3](:zip, c) }
puts combined.inspect
Drag options to blanks, or click blank then click option'
Azip
Bmap
Csend
Deach
Attempts:
3 left
💡 Hint
Common Mistakes
Using each instead of map or wrong method names.