<HTML>
<body>
</body>
<Script>
function compareNumeric (a,b){
if(a > b) return -1; // returning -1 means first argument ascends b
if(a == b) return 0;
if (a < b) return 1; // returning 1 means b is asceds a
}
let arr = [5, 2, 1, -10, 8];
arr.sort(compareNumeric);
// ... your code to sort it in the reverse order
alert( arr ); // 8, 5, 2, 1, -10
</Script>
</HTML>
<body>
</body>
<Script>
function compareNumeric (a,b){
if(a > b) return -1; // returning -1 means first argument ascends b
if(a == b) return 0;
if (a < b) return 1; // returning 1 means b is asceds a
}
let arr = [5, 2, 1, -10, 8];
arr.sort(compareNumeric);
// ... your code to sort it in the reverse order
alert( arr ); // 8, 5, 2, 1, -10
</Script>
</HTML>
댓글
댓글 쓰기