So to answer your questions regarding operators like <<
or ||= []
:
<<
appends an element to an array (or appends strings), in the case above it’s used to append thecomment
object to either the results array or or the threaded thingy.||=
basically means, if left-hand-side is undefined then evaluate & assign right-hand-side ([]
is the same asArray.new
) => “ifmap[parent]
is undefined, initialize it withArray.new
– else do nothing”
To method above creates an array with parent comments (results
) and a hash with child comments (map
).
solved Can somenone translate this from Ruby to Python. Its a basic map function [closed]