Array Methods
sort, reverse, uniq, flatten, compact, include?, index, sample and zip.
Example
a = [3, 1, nil, 2, 3]
b = a.compact
puts b.sort.inspect, b.uniq.inspect, b.reverse.inspect, b.include?(2)
puts [1, [2, [3]]].flatten.inspect, [1, 2].zip(["a", "b"]).inspectResult
[1, 2, 3, 3] [3, 1, 2] [3, 2, 1, 3] true [1, 2, 3] [[1, "a"], [2, "b"]]
Exercise
Remove nils.
a.Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.