Created
November 13, 2022 08:39
-
-
Save ehsaneona/db25854b1f9922752c8cb9b891b0b79c to your computer and use it in GitHub Desktop.
Moving an Index from the Array and moving to the specified Index
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const swapArrayIndex = (array, currentIndex, moveIndex) => { | |
| if (!array[moveIndex] || !array[currentIndex]) return array; | |
| let changedArray = [...array]; | |
| changedArray[currentIndex] = array[moveIndex]; | |
| changedArray[moveIndex] = array[currentIndex]; | |
| return changedArray; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment