Created
          April 20, 2015 00:53 
        
      - 
      
- 
        Save assertchris/4b4091ed5ed99bb23e20 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function bubble(data) { | |
| var length = data.length; | |
| while (length) { | |
| for (var i = 1; i < length; i++) { | |
| var prev = data[i - 1]; | |
| var next = data[i]; | |
| if (prev > next) { | |
| data[i] = prev; | |
| data[i - 1] = next; | |
| } | |
| } | |
| length--; | |
| } | |
| return data; | |
| } | |
| console.log( | |
| bubble([5, 4, 7, 3, 2, 8, 1, 9, 0, 6]) | |
| ); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment