Q:

Write a Ruby program to set 5 to 1 whether there is a 3 immediately followed by a 4 in a given array of integers (length 3)

0

Write a Ruby program to set 5 to 1 whether there is a 3 immediately followed by a 4 in a given array of integers (length 3).

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

def check_array(nums)
     num1 = nums[0], nums[1], nums[2]
	if(nums[0] == 3 && nums[1] == 5)
			num1[1] = 1;
	end		
	if(nums[1] == 3 && nums[2] == 5)
			num1[2] = 1;
	end		
	return num1;
end
print check_array([1, 3, 5]),"\n" 
print check_array([3, 5, 6]),"\n" 
print check_array([3, 9, 5]) 
Output:
[1, 3, 1]
[3, 1, 6]
[3, 9, 5]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now