Last active
October 26, 2017 20:10
-
-
Save herber/8e949021fe6910ba84cee6d492f774de to your computer and use it in GitHub Desktop.
A simple bubble sort function.
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
const bubbleSort = (arr) => { | |
for (let i = arr.length - 1; i >= 0; i--){ | |
for(let j = 1; j <= i; j++){ | |
if(arr[j - 1] > arr[j]){ | |
const temp = arr[j - 1]; | |
arr[j - 1] = arr[j]; | |
arr[j] = temp; | |
} | |
} | |
} | |
return arr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment