daily pastebin goal
59%
SHARE
TWEET

Untitled

a guest Nov 9th, 2018 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let numbers = [4, 5, 3, 1, 2];
  2.  
  3. for (var i = 0; i < numbers.length - 1; i++) {
  4.     console.log(`i = ${i}; numbers = ${numbers}`)
  5.     for (var j = i; j < numbers.length; j++) {
  6.         console.log(`j = ${j}`);
  7.         console.log(`Is ${numbers[i]} > ${numbers[j]}?`);
  8.         if(numbers[i] > numbers[j]) {
  9.             console.log(`Yes. numbers[${j + 1}] is now ${numbers[j]}`);
  10.             // swap numbers[j] with numbers[i]
  11.             let tmp = numbers[j];
  12.             numbers[j] = numbers[i];
  13.             numbers[i] = tmp;
  14.         } else {
  15.             console.log('no');
  16.         }
  17.         console.log(`numbers = ${numbers}`)
  18.     }
  19. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top