숫자 배열을 받는 JavaScript 함수를 작성해야 합니다.
그런 다음 함수는 숫자 배열을 제자리에 정렬해야 합니다(오름차순 또는 내림차순).
예시
이에 대한 코드는 -
const arr = [2, 5, 19, 2, 43, 32, 2, 34, 67, 88, 4, 7];
const sortIntegers = (arr = []) => {
const sorterAscending = (a, b) => {
return a - b;
};
const sorterDescending = (a, b) => {
return b - a;
};
arr.sort(sorterAscending);
};
sortIntegers(arr);
console.log(arr); 출력
콘솔의 출력은 -
[ 2, 2, 2, 4, 5, 7, 19, 32, 34, 43, 67, 88 ]