Created
January 12, 2017 22:34
-
-
Save MarcusHurney/d01d462542da2455b383600d2a7c7569 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
var myArray = [1,3,2,2,10,9,9,8,7,13,6,4]; | |
var mysteryFunction = function(array) { | |
var hashHadChange; | |
for (var i = 0; i < array.length - 1; i++) { | |
hashHadChange = false; | |
for (var x = 0; x < array.length - 1; x++) { | |
if (array[x] > array[x+1]) { | |
var temp = array[x]; | |
array[x] = array[x+1]; | |
array[x + 1] = temp; | |
hashHadChange = true; | |
} | |
} | |
if (!hashHadChange) { | |
return array; | |
} | |
} | |
return array; | |
}; | |
console.log(mysteryFunction(myArray)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment