diff --git a/find_max.rb b/find_max.rb new file mode 100644 index 0000000..2c93e3f --- /dev/null +++ b/find_max.rb @@ -0,0 +1,19 @@ + +# Find the maximum element between index 0 and max_index, exclusive + +def find_max(array, max_index) + max = nil + if max_index == 0 + puts "Array is empty" + else + max = array[0] + index = 0 + while index < max_index + if max < array[index] + max = array[index] + end + index += 1 + end + end + return max +end