ruby - Codefights No implicit conversion of String into Integer -
here code:
def alllongeststrings(inputarray) array = array.new inputarray.each |i| if inputarray[i].length == inputarray.max.length array << inputarray[i] end end return array end inputarray = ["aba", "aa", "ad", "vcd", "aba"]
it says "no implicit conversion of string integer" , can't figure out. doing wrong?
error here:
if i.length == inputarray.max.length # instead of inputarray[i] array << end
but suggest use select:
input_array = ["aba", "aa", "ad", "vcd", "aba"] max_length = input_array.max.length input_array.select { |el| el.length == max_length } #=> ["aba", "vcd", "aba"]
Comments
Post a Comment