Skip to content

Instantly share code, notes, and snippets.

@galElmalah
Last active June 11, 2020 09:51
Show Gist options
  • Save galElmalah/9b6c55c50ffcb3f5cb4d9c5ba5cc3c6e to your computer and use it in GitHub Desktop.
Save galElmalah/9b6c55c50ffcb3f5cb4d9c5ba5cc3c6e to your computer and use it in GitHub Desktop.
bubble sort implementation
const bubbleSort = (array, onAction) => {
for (let i = 0; i < array.length; i++) {
for (let j = 0; j < array.length; j++) {
if (array[j] > array[j + 1]) {
let tmp = array[j];
array[j] = array[j + 1];
array[j + 1] = tmp;
}
}
}
return array;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment