Skip to content

Instantly share code, notes, and snippets.

@alexcraviotto
Created February 2, 2022 19:55
Show Gist options
  • Save alexcraviotto/5a0dc7ef9af85089931bedf3386f0cc3 to your computer and use it in GitHub Desktop.
Save alexcraviotto/5a0dc7ef9af85089931bedf3386f0cc3 to your computer and use it in GitHub Desktop.
Bubble Sort implemented with TypeScript
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