syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me

Question:
In Ruby what does flatten() do?

The method, flatten(), squashes nesting-structure out of an Array so it contains only elements and no other Arrays:
dan@feb ~/x611 $ 
dan@feb ~/x611 $ irb
irb(main):001:0> 
irb(main):002:0* 
irb(main):003:0* myarray = ['hello', 'world', ['hi', ['calif', 'tex']]]
=> ["hello", "world", ["hi", ["calif", "tex"]]]
irb(main):004:0> myarray.flatten()
=> ["hello", "world", "hi", "calif", "tex"]
irb(main):005:0> quit
dan@feb ~/x611 $ 
dan@feb ~/x611 $ 
flatten() reminds me of flatMap() in Spark:
spark_flatmap


syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me