Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
let str = "adrianstatescu"
console.log(str)
let arr = [...str.toString()]
let finished = 0, swapped, size = arr.length;
while(!finished) {
swapped = 0
for(var i = 0; i < size - 1; ++i) {
if(arr[i] > arr[i+1]) {
let holder = arr[i];
arr[i] = arr[i+1];
arr[i+1] = holder;
swapped = 1;
}
}
if(swapped) size--; else finished = 1;
}
console.log(arr.join(""));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment