Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Function for multidimensional array flattening
- def combine_nested_arrays(arr, all=[])
- arr.each do |item|
- if item.class != Array
- all << item
- else
- combine_nested_arrays(item, all)
- end
- end
- all
- end
- puts combine_nested_arrays([[1,2,[3]],4]).to_s
Add Comment
Please, Sign In to add comment