Skip to content

Instantly share code, notes, and snippets.

@mdimai666
Created May 14, 2018 02:50
Show Gist options
  • Save mdimai666/463c17b2cc807605df7d3178a6aede46 to your computer and use it in GitHub Desktop.
Save mdimai666/463c17b2cc807605df7d3178a6aede46 to your computer and use it in GitHub Desktop.
function array_move(arr, old_index, new_index) {
if (new_index >= arr.length) {
var k = new_index - arr.length + 1;
while (k--) {
arr.push(undefined);
}
}
arr.splice(new_index, 0, arr.splice(old_index, 1)[0]);
return arr; // for testing
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment