SHARE
TWEET

Untitled

a guest Sep 19th, 2019 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function bubbleSort(numbers: number[]): number[] {
  2.     let sortedNumbers = numbers;
  3.  
  4.     for (let i = 0; i < sortedNumbers.length; i++) {
  5.         for (let j = 1; j < sortedNumbers.length; j++) {
  6.             if (sortedNumbers[j - 1] > sortedNumbers[j]) {
  7.                 const temp = sortedNumbers[j - 1];
  8.                 sortedNumbers[j - 1] = sortedNumbers[j];
  9.                 sortedNumbers[j] = temp;
  10.             }
  11.         }
  12.     }
  13.  
  14.     return sortedNumbers;
  15. }
  16.  
  17. const numbers = [5, 15, 14, 1, 26, 0, 99]
  18. console.log(bubbleSort(numbers));
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