Write a method that takes in a string and an array of indices in the
string. Produce a new string, which contains letters from the input
string in the order specified by the indices of the array of indices.
This is how I solved it.
def scramble_string(string, positions)
letters = string.split(//)
unscrambled_arr = Array.new
count = 0
while count < positions.length
num = positions[count]
unscrambled_arr.push(letters[num])
count += 1
end
unscrambled_arr.join
end
I figure there must be a simpler way to solve it. I’m guessing it can be
done with a regular expression. Looking for a seasoned ruby programmer
to show me how they would do it.