Skip to content

Instantly share code, notes, and snippets.

@GGrassiant
Created April 18, 2021 11:12
Show Gist options
  • Select an option

  • Save GGrassiant/e518dca88c73aa39977fa9271d9db6c5 to your computer and use it in GitHub Desktop.

Select an option

Save GGrassiant/e518dca88c73aa39977fa9271d9db6c5 to your computer and use it in GitHub Desktop.
Simpe Bubble Sort
const bubbleSort = (array) => {
let isSorted = false;
while (!isSorted) {
isSorted = true;
for (let i = 0; i < array.length - 1; i++) {
if (array[i] > array[i + 1]) {
[array[i], array[i + 1]] = [array[i + 1], array[i]];
isSorted = false;
}
}
}
return array;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment