4 ms·
Such a great site. The page on flattening arrays blows me away at how different and beautiful some languages can be (especially Ruby and Erlang's take). http:/
by mishmash 16y ago
Such a great site. The page on flattening arrays blows me away at how different and beautiful some languages can be (especially Ruby and Erlang's take).
http://rosettacode.org/wiki/Flatten_a_list http://rosettacode.org/wiki/Flatten_a_list
- oofoe 16y agoI'll give you Erlang, but the Ruby solution is cheating rather.
- judofyr 16y agoHere's a better Ruby version: module Enumerable def custom_flatten inject([]) do |result, element| if element.respond_to?(:custom_flatten) result.concat(element.custom_flatten) else result.push(element) end end end end Works on all Enumerables (Array, Hash, Set, etc)
- woodall 16y agoHow is Ruby's method and different than Groovy or JavaScript? I think their all pretty neat. Goes to show that there is always more than one way to skin a list.
- mishmash 16y agoTrue. I guess built-in functions shouldn't count.