Advertisement
Guest User

Untitled

a guest
May 21st, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.28 KB | None | 0 0
  1. function convertArray(arr, N) {
  2. let result = [], swapIndex = -1;
  3. for (let i = 0; i < arr.length; i++) {
  4. swapIndex = arr[(N * (i%N)) + i/N];
  5. while (swapIndex < i) {
  6. swapIndex = arr[(N * (swapIndex%N)) + swapIndex/N];
  7. }
  8. swap(arr, swapIndex, i);
  9. }
  10. return result;
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement