Oracle interview question

Reverse the two consecutive elements in the given string

Interview Answer

Anonymous

23 May 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")