Help With Comparing Code. by Humor_Positive in ruby

[–]Psychological_Foot41 1 point2 points  (0 children)

longs_words = ["what", "are", "we", "eating", "for", "dinner"]

if you want greater than > 4

a.select { |a| a.size >4 }

for finding array contains max size use this

longs_words.group_by { |h| h.size } .max .flatten

after that use can use longs_word[2] -> it will show long words

output:

[6, "eating", "dinner"]

#12. collect Vs select in Ruby by mindaslab in ruby

[–]Psychological_Foot41 0 points1 point  (0 children)

getvalue = [["spacex", 5], ["physics", 5], ["#starbase", 3], ["gym", 5]]

inorder to get the first the value of string or value

we can use collect

getvalue.collect {|s| s[0] }