samedi 29 juillet 2017

Codewars Snail Test Wrong or Code Wrong?

I think I have a pretty cool solution to this codewars challenge but I am failing the last test because it is adding an extra 1 to the beginning of my array and I don't know why! In IRB my code seems to work fine.

@arr = []

def snail(array)
  array.to_a.empty? ? (return @arr.flatten) : @arr << array.shift
  snail(array.transpose.reverse)
end

When snail([[4, 5, 6], [7, 8, 9]]) expected [1, 2, 3, 6, 9, 8, 7, 4, 5] but got [1, 1, 2, 3, 6, 9, 8, 7, 4, 5]

Aucun commentaire:

Enregistrer un commentaire