Write a program that sorts in ascending order when N numbers are input and outputs them.
The sorting method is selection sort.
6
13 5 11 7 23 15
Prints a sequence sorted in ascending order.
5 7 11 13 15 23
function solution(arr) {
let answer = arr;
for (let i = 0; i < arr.length - 1; i++) {
let idx = i;
for (let j = i + 1; j < arr.length; j++) {
if (arr[j] < arr[idx]) idx = j;
}
[arr[i], arr[idx]] = [arr[idx], arr[i]];
}
return answer;
}