Pregunta de entrevista de Oracle

Reverse the two consecutive elements in the given string

Respuesta de la entrevista

Anónimo

23 de may de 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")