Skip to content

Instantly share code, notes, and snippets.

@yuriy-o
Created September 27, 2022 13:04
Show Gist options
  • Save yuriy-o/708ece48418665c09b217d339bd4d770 to your computer and use it in GitHub Desktop.
Save yuriy-o/708ece48418665c09b217d339bd4d770 to your computer and use it in GitHub Desktop.
bubble sorting
// ---- bubble sorting ----
const langs = ['python', 'javascript', 'c++', 'haskel', 'php', 'ruby'];
langs.sort();
for (let i = 0; i < langs.length - 1; i += 1) {
for (let j = i + 1; j < langs.length; j += 1) {
const item1 = langs[i]; // python
const item2 = langs[j];
if (item2[0] < item1[0]) {
langs[j] = item1;
langs[i] = item2;
}
}
}
console.log(langs);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment