Skip to content

Instantly share code, notes, and snippets.

@kmylo
Last active December 19, 2019 19:15
Show Gist options
  • Save kmylo/f097bdf39490f39bab844b8e343a8291 to your computer and use it in GitHub Desktop.
Save kmylo/f097bdf39490f39bab844b8e343a8291 to your computer and use it in GitHub Desktop.
Swap two array items position
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