Domanda di colloquio di Oracle

Reverse the two consecutive elements in the given string

Risposta di colloquio

Anonimo

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