Skip to content

Instantly share code, notes, and snippets.

@C-Rodg
Created November 4, 2016 01:48
Show Gist options
  • Select an option

  • Save C-Rodg/cb73149252e0f29d71470856430fc3e1 to your computer and use it in GitHub Desktop.

Select an option

Save C-Rodg/cb73149252e0f29d71470856430fc3e1 to your computer and use it in GitHub Desktop.
Mutate an input array so that each element ends up in their index from a corresponding array.
let arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
let idx = [4, 3, 5, 0, 6, 1, 2];
arr = idx.map((idxVal, index) => {
return arr[idx.indexOf(index)];
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment