Search⌘ K

Exercise 4: Replace an Element in the Array

Practice replacing an element in a Ruby array by adding code at a specific line. Understand how to manipulate arrays effectively within given constraints to produce desired outputs.

We'll cover the following...

Problem statement

Given an array of at least size four, add a line in the code below so that the program returns 99 when executed.

Note: You can only insert code at line 3, and you can’t make changes to existing lines of code.

Try it yourself

Ruby
def replace_element(input_array)
# Start your code here
return input_array[3]
end