【发布时间】:2021-12-10 08:43:29
【问题描述】:
我有字符串数组和整数数组,它们表示字符串的索引以及它们需要交换的顺序。我需要将索引 X 与以下索引交换,并对下一对数字执行相同操作。
我认为必须有一种方法可以用数字替换字符串的索引并相应地交换字符串位置。
例如:
```
Array = ["A", "B", "C", "D", "E", "F"]
SwapIndexes = [4, 2, 0, 3, 1, 5]
`#=>can also be understood as [4<to>2, 0<to>3, 1<to>5]`
```
输出应该是:
```
NewArray = ["D", "F", "E", "A", "C", "B"]
`#=>Indexes have beem swaped according to each pair of numbers in SwapIndexes`
```
【问题讨论】:
标签: arrays ruby indexing compare-and-swap