Last active
January 3, 2016 12:59
-
-
Save gmcerveny/8466270 to your computer and use it in GitHub Desktop.
This file contains 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
var numbers = [6, 3, 2, 9]; | |
console.log(numbers); | |
do { | |
unsorted = true; | |
for (var i = 0; i < numbers.length - 1; i += 1) { | |
var j = i + 1; | |
if (numbers[i] > numbers[j]){ | |
var hold = numbers[i]; | |
numbers[i] = numbers[j]; | |
numbers[j] = hold; | |
unsorted = false; | |
} | |
} | |
} while (!unsorted); | |
console.log(numbers); |
This file contains 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
var numbers = [1,3,3,5]; | |
var ordered = [numbers.pop()]; | |
console.log(numbers); | |
while (numbers.length > 0){ | |
var popped = numbers.pop(); | |
for (var i = 0; i < ordered.length; i++) { | |
if ( popped <= ordered[i]) { | |
ordered.splice(i, 0, popped); | |
break; | |
} | |
} | |
} | |
console.log(ordered); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment