【Javascript】配列の整列(ソート,Sort)
<html> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <meta http-equiv="Content-Language" content="ja"> <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> <title></title> <script type="text/javascript"> <!-- var n = new Array( 59, 24, 0, 4, -357, 35, 161, -3, 5455); document.write('元内容:' + n + '<br />'); // 昇順ソート(Ascending) document.write('昇順ソート(Ascending):' + n.sort(compNumber) + '<br />'); // 降順ソート(Descending) document.write('降順ソート(Descending):' + n.sort(compNumberReverse) + '<br />'); function compNumber(a, b) { return a - b; } function compNumberReverse(a, b) { return b - a; } //--> </script> </head> <body> </body> </html>