How to convert 2D array to a 1D array in Ruby

1 Answer

0 votes
arr = [["a", "b", "c"], ["d", "e", "f", "g"], ["h", "i"]]

p arr

arr.flatten!
p arr
 
 
 
# run:
   
# [["a", "b", "c"], ["d", "e", "f", "g"], ["h", "i"]]
# ["a", "b", "c", "d", "e", "f", "g", "h", "i"]

 



answered Sep 1, 2020 by avibootz
...