Skip to content

Instantly share code, notes, and snippets.

@YounglanHong
Created June 22, 2020 06:29
Show Gist options
  • Select an option

  • Save YounglanHong/b827004b3a3e4d971a4e02ce65834b61 to your computer and use it in GitHub Desktop.

Select an option

Save YounglanHong/b827004b3a3e4d971a4e02ce65834b61 to your computer and use it in GitHub Desktop.
function bubble(arr) {
let result = arr.slice(); // 원본 배열 복사
for (let i = 0; i < result.length - 1; i++) {
for (let j = 0; j < result.length - i; j++) {
if (result[j] > result[j + 1]) {
let temp = result[j];
result[j] = result[j+1];
result[j+1] = temp;
}
}
}
return result;
}
const items = prompt('입력해주세요.').split(' ').map((n) => {
return parseInt(n, 10);
});
console.log(bubble(items));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment