Created
June 22, 2020 06:29
-
-
Save YounglanHong/b827004b3a3e4d971a4e02ce65834b61 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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