Oracle Interview Question

Reverse the two consecutive elements in the given string

Interview Answer

Anonymous

May 23, 2019

def reverse_consecutive_str(str) old_arr = str.chars arr = [] old_arr.each_with_index do |ele, index| arr.push("#{old_arr[index+1]}#{ele}") if index.even? end arr.join("") end reverse_consecutive_str("elephant")