HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
📝
프론트엔드 스쿨 교안(1기)
/
📝
(코테준비) 자료구조 및 알고리즘
/
☝
JS 100제 - 1권
/
🔥
문제50
/
✔️
답안
✔️

답안

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));