Created
September 27, 2022 13:04
-
-
Save yuriy-o/708ece48418665c09b217d339bd4d770 to your computer and use it in GitHub Desktop.
bubble sorting
This file contains 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
// ---- 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