I have array const arr = [1,2,3,4]
I want to get 4 different arrays by swapping a number pairs in this array.
I. e. the outcome of this array would be:
1st: [2,1,3,4]
2nd: [1,3,2,4]
3rd: [1,2,4,3]
4rd: [4,2,3,1]
(swapping first and last elements)
I know Object.assign
help's to avoid mutations but not sure how to implement it.
more explanation:
- taking an original arr
- swapping the first pair of numbers
- returning
[2,1,3,4]
repeating
- taking an original arr
- swapping the second pair of numbers
- returning
[1,3,2,4]
etc.