Advertisement
here2share

$ JS Shuffled Sequences

Jan 13th, 2023
1,128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Shuffled Sequences</title>
  5. </head>
  6. <body>
  7. <div id="output"></div>
  8. <script>
  9. let n = 10;
  10. let counter = 0;
  11. let output = document.getElementById("output");
  12. let integers = [];
  13. for (let i = -n; i <= n; i++) {
  14.     integers.push(i);
  15. }
  16.  
  17. for (let i = 0; i <= 18; i++) {
  18.     integers = integers.concat(integers);
  19. }
  20.  
  21. let L = integers.length;
  22.  
  23. function shuffle() {
  24.     let element = integers.splice((counter ** 5) % L, 1)[0];
  25.     integers.push(element);
  26. }
  27.  
  28. function printSequence() {
  29.     shuffle();
  30.     output.innerHTML += integers[L - 1] + " ";
  31.     counter++;
  32.     if (counter > L) {
  33.         counter = 0;
  34.     }
  35.     setTimeout(printSequence, 1);
  36. }
  37. printSequence();
  38. </script>
  39. </body>
  40. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement