일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- Sort
- 등차수열의 항 찾기
- 일반 형제 선택자 결합
- 고차함수
- 배열의 내림차순
- 양방향 연결리스트
- 인접 형제 선택자 결합
- nth-child()
- Link
- invalid assignment left-hand side
- map()
- classList.contains(string)
- 배열과 연결리스트의 차이
- 객체
- for..of
- innerhtml
- 범용 선택자
- filter()
- CSS
- 백준알고리즘
- visibility : hidden
- Em
- Array.from()
- indexOf
- 가상 요소 선택자
- disabled
- 단방향 연결리스트
- 배열의 오름차순
- 쌍방향 연결리스트
- display : none
- Today
- Total
목록Sort (3)
프론트엔드 센트럴파크 (☞゚ヮ゚)☞

let nums = [ 1, -1, 4, 0, 10, 20, 12]; console.log(nums.sort()); console.log(nums.reverse()); let ascending_order = function(x,y) { return x - y; }; let descending_order = function(x,y) { return y - x; }; console.log(nums.sort(ascending_order)); console.log(nums.sort(descending_order)); 예를들어, ascending_order 함수에서 20과 12를 비교한다고 가정해보자 함수의 매개변수에 따라 x=20, y=12가 된다. x - y 는 20 - 12가 되고 결과는 8이 된다. 8은 ..

배열에 대문자와 소문자가 섞여 있는 경우, toUpperCase() 함수를 이용해 대문자로 다 바꾼 후 콜백함수를 사용하여 문자 크기를 비교한다. 오름차순 let ascending_order = function(x,y) { x = x.toUpperCase(); y = y.toUpperCase(); if (x > y) return 1; else if (y > x) return -1; else return 0; }; let fruits = ["apple", "Orange", "orange", "melon"]; console.log(fruits.sort(ascending_order)); 내림차순 let descending_order = function(x,y) { x = x.toUpperCase(); y = ..

sort() : 오름차순으로 정렬 let num = [1, -1, 4, 5, 2, 0]; console.log(num.sort()); reverse() : 좌우반전으로 정렬 let num = [1, -1, 4, 5, 2, 0]; console.log(num.reverse()); sort와 reverse를 순차적으로 사용하게 되면 내림차순으로 정렬이 가능하다. let num = [1, -1, 4, 5, 2, 0]; console.log(num.sort()); console.log(num.reverse()); 배열의 데이터가 문자열일 경우, 알파벳 순으로 정렬이 된다. let fruits = ["apple", "banana", "watermelon", "melon"]; console.log(fruits.so..