Complete the code to flatten the nested arrays using flat_map.
nested = [[1, 2], [3, 4], [5, 6]] flat = nested.[1] { |arr| arr } puts flat.inspect
The flat_map method maps and flattens one level of nested arrays, producing a single flat array.
Complete the code to flatten and double each number in the nested arrays.
nested = [[1, 2], [3, 4], [5, 6]] result = nested.[1] { |arr| arr.map { |n| n * 2 } } puts result.inspect
flat_map applies the block to each sub-array, then flattens the result into a single array.
Fix the error in the code to flatten nested arrays of strings into a single array of characters.
words = [["hi", "there"], ["ruby", "code"]] chars = words.[1] { |word_arr| word_arr.map(&:chars) } puts chars.flatten.inspect
Using flat_map here flattens one level after mapping, so you don't need to call flatten separately.
Fill both blanks to flatten and convert nested arrays of numbers to strings.
nested = [[1, 2], [3, 4], [5, 6]] result = nested.[1] { |arr| arr.[2](&:to_s) } puts result.inspect
flat_map flattens the outer array after mapping, and map converts each number to a string.
Fill all three blanks to flatten nested arrays and select only even numbers as strings.
nested = [[1, 2], [3, 4], [5, 6]] result = nested.[1] { |arr| arr.[2] { |n| n.[3] }} puts result.inspect
flat_map flattens the array, select filters even numbers, and even? checks if a number is even.