링크 조회 : 94
<SCRIPT>
var numArray=[0,21,1225,1247,11,1119,8];
document.write('numArray='+numArray+'<BR><BR>') // 배열변수 출력
function sortSame(a,a){ return a-a}; // 인수 a,a로 배열변수 정렬에 변화 없다.
document.write(numArray.sort(sortReverse)); // 기능함수 호출하여 출력
function sortNumbers(a,b){ return a-b}; // 인수 a,b로 배열변수를 오름차 순으로 정렬
document.write(numArray.sort(sortNumbers)+'<BR>'); // 기능함수 호출하여 출력
function sortReverse(b,a){ return a-b}; // 인수 b,a로 배열변수를 내림차 순으로 정렬
document.write(numArray.sort(sortReverse)); // 기능함수 호출하여 출력
</SCRIPT>
<SCRIPT>
function reverseSort(b,a){
if(a>b) return 1;
if(a<b) return -1;
return 0;
}
var numArray=[0,21,1225,1247,11,1119,8]
document.write(numArray+'<BR>');
document.write(numArray.sort(reverseSort));
</SCRIPT>
-----------=-------------
JS에서 배열을 소팅할 때 기능함수를 사용하여, 소팅 방법을 정할 수 있다.
제목 | 작성자 | 날짜 |
---|---|---|
공대여자 | ||
공대여자 | ||
mins01 | ||
mins | ||
mins | ||
mins | ||
mins | ||
mins | ||
mins | ||
mins | ||
mins | ||
mins | ||
mins | ||
mins | ||
mins | ||
mins | ||
mins | ||
mins |