Skip to content

Instantly share code, notes, and snippets.

@sarfarazansari
Created September 13, 2018 11:59
Show Gist options
  • Select an option

  • Save sarfarazansari/d9a087ec3dc1dec051b6767497ba9e5e to your computer and use it in GitHub Desktop.

Select an option

Save sarfarazansari/d9a087ec3dc1dec051b6767497ba9e5e to your computer and use it in GitHub Desktop.

Revisions

  1. sarfarazansari created this gist Sep 13, 2018.
    10 changes: 10 additions & 0 deletions move-array-position.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    public moveArrayPosition(arr: any[], oldPosition: number, newPosition: number) {
    if (newPosition >= arr.length) {
    let k = newPosition - arr.length + 1;
    while (k--) {
    arr.push(undefined);
    }
    }
    arr.splice(newPosition, 0, arr.splice(oldPosition, 1)[0]);
    return arr;
    }