This is a bit of a n00b question. I'm trying to figure out how I can refactor a nested each loop like the one below so that I am not declaring extra variables that I won't need later and so that my code runs quicker.
some_array = [["one", 2, 3], ["two", 3, 4], ["three", 4, 5]]
output = {}
some_array.each do |a|
current_group = []
another_array.each do |b|
current_group << b if something == true
end
output[a[0]] = current_group
end
The output
is returned as a hash of arrays. some_array
is a nested array where the first element in each sub-array is a string and another_array
is an array of hashes.
group
? – Mark Reed 18 mins ago.inject
– Jon 17 mins agoa
? – ruakh 15 mins agogroup
isa
. – ACIDSTEALTH 13 mins agosomething
? – Amit Joki 11 mins ago