lundi 18 novembre 2019

Write a function that returns the position or positions of the lowest valued integer and can handle this array or any array

figures = [-1, -7, 1, 5, -7, 0];

You are not allowed to use .map , each, max or other similar ruby methods. I got this question in a coding challenge and I was unable to produce a good answer.

def getArrayIndex(number, i) 
  n=1 
  if number[i] < number[i+=n] 
    puts number[i] 
  else 
    puts number[i+=n] 
  end 
end 
p getArrayIndex(figures, 0) 

Aucun commentaire:

Enregistrer un commentaire