Created
February 2, 2022 19:55
-
-
Save alexcraviotto/5a0dc7ef9af85089931bedf3386f0cc3 to your computer and use it in GitHub Desktop.
Bubble Sort implemented with TypeScript
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
export const bubbleSort = (array: number[]): number[] => { | |
let aux: number; | |
for(let i = 1; i < array.length; i++){ | |
for(let j = 0; j < array.length - i; j++){ | |
if(array[j] > array[j+1]){ | |
aux = array[j]; | |
array[j] = array[j+1]; | |
array[j+1] = aux; | |
} | |
} | |
} | |
return array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment