[JavaScript General] 数値とテキストのソート
memo.
[markdown]
> [Array.prototype.sort() – JavaScript | MDN](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
>
> 配列の要素をソートします。
compareFunction (比較関数) を与えることで、配列の要素が返値に基づきソートされる。
“`javascript
array.sort(function compareFunction(a, b) {
下記の文字列や数値の処理
});
“`
文字列のソート。
“`javascript
function compare(a, b) {
if (a < b) { return -1; }
if (a > b) { return 1; }
return 0;
}
“`
数値のソート。
“`javascript
function compareNumbers(a, b) {
return a – b;
}
“`
> [#01 開発の準備を整えよう | 【旧版】jQueryで作るテーブルのソート機能 – プログラミングならドットインストール](http://dotinstall.com/lessons/tablesort_jquery/25001)
See the Pen jQuery: Table sort by DriftwoodJP (@DriftwoodJP) on CodePen.
[/markdown]