Advertisement
Diriector_Doc

Random stort

Feb 27th, 2022
1,214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function sort(A) {
  2.     loop: while (true) {
  3.         let i1 = Math.trunc(Math.random() * A.length),
  4.             i2 = Math.trunc(Math.random() * A.length);
  5.         if (i1 > i2)
  6.             if (A[i1] < A[i2])
  7.                 [A[i1], A[i2]] = [A[i2], A[i1]];
  8.             else
  9.         if (A[i2] < A[i1])
  10.             [A[i1], A[i2]] = [A[i2], A[i1]];
  11.         for (let i = 1; i < A.length; i++)
  12.             if (A[i - 1] > A[i])
  13.                 continue loop;
  14.         return A
  15.     }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement