### How can I change the order of two arrays when one array is sorted?

19
views
0
4 months ago by
If I have:
var arrayOne = ["dog", "cat", "hamster", "horse"]​

and

var arrayTwo = [3, 2, 4, 1]

How can I assign 3 to dog, 2 to cat, 4 to hamster, and 1 to horse so that if I sort arrayTwo from biggest integer to smallest, it will automatically do that for arrayOne too. In result it would print out:

var arrayOne = ["hamster", "dog", "cat", "horse"]
var arrayTwo = [4, 3, 2, 1]

What code is easiest and simplest for this?

Thanks in Advance! :)

Community: Swift