Last active
December 19, 2019 19:15
-
-
Save kmylo/f097bdf39490f39bab844b8e343a8291 to your computer and use it in GitHub Desktop.
Swap two array items position
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
Array.prototype.move = function(from, to) { | |
this.splice(to, 0, this.splice(from, 1)[0]); | |
}; | |
const swapPositions = (array, a ,b) => { | |
[array[a], array[b]] = [array[b], array[a]] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment