{"id":2722,"date":"2023-06-03T14:25:16","date_gmt":"2023-06-03T05:25:16","guid":{"rendered":"http:\/\/attacktube.com\/?p=2722"},"modified":"2023-06-05T07:15:38","modified_gmt":"2023-06-04T22:15:38","slug":"%e3%80%90javascript%e3%80%91sort%e3%83%a1%e3%82%bd%e3%83%83%e3%83%89-%e3%81%9d%e3%81%ae3","status":"publish","type":"post","link":"https:\/\/attacktube.com\/?p=2722","title":{"rendered":"\u3010JavaScript\u3011sort\u30e1\u30bd\u30c3\u30c9 \u305d\u306e3"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">sort\u3092\u4f7f\u3063\u3066\u914d\u5217\u3092\u4e26\u3073\u66ff\u3048\u308b\u3002<br>\u914d\u5217\u306e\u8981\u7d20\u304c\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u5834\u5408\u306esort\u3092\u8003\u3048\u308b\u3002<br>\u914d\u5217s\u306e\u8981\u7d20\u304c\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u5834\u5408\u306b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u540d\u300cfirst\u300d\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u308b\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<br>\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-3461056110605997\" crossorigin=\"anonymous\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-3461056110605997\" data-ad-slot=\"3137443461\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n<br>\n\n\n\n<p class=\"wp-block-paragraph\">first\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u308b\u6bd4\u8f03\u95a2\u6570CompareArray001\u306f\u6b21\u306e\u901a\u308a\u3002<\/p>\n\n\n\n<pre><code>\nconst s = [{\n        first: &quot;Joe&quot;,\n        last: &quot;DeRita&quot;,\n        aa: &quot;zz&quot;,\n        kk: &quot;wq&quot;\n    },\n    {\n        first: &quot;ZCurly&quot;,\n        last: &quot;Howard&quot;,\n        aa: &quot;ab&quot;,\n        kk: &quot;bb&quot;\n    },\n    {\n        first: &quot;ACurly&quot;,\n        last: &quot;Howard&quot;,\n        aa: &quot;ab&quot;,\n        kk: &quot;aa&quot;\n    },\n    {\n        first: &quot;Joe&quot;,\n        last: &quot;DeRita&quot;,\n        aa: &quot;ab&quot;,\n        kk: &quot;zz&quot;\n    },\n    {\n        first: &quot;Moe&quot;,\n        last: &quot;Howard&quot;,\n        aa: &quot;ab&quot;,\n        kk: &quot;aa&quot;\n    },\n    {\n        first: &quot;Joe&quot;,\n        last: &quot;Besser&quot;,\n        aa: &quot;ab&quot;,\n        kk: &quot;aa&quot;\n    },\n    {\n        first: &quot;Shemp&quot;,\n        last: &quot;Howard&quot;,\n        aa: &quot;ab&quot;,\n        kk: &quot;aa&quot;\n    },\n    {\n        first: &quot;Larry&quot;,\n        last: &quot;Fine&quot;,\n        aa: &quot;ab&quot;,\n        kk: &quot;aa&quot;\n    },\n    {\n        first: &quot;Curly&quot;,\n        last: &quot;Howard&quot;,\n        aa: &quot;ab&quot;,\n        kk: &quot;aa&quot;\n    },\n    {\n        first: &quot;BCurly&quot;,\n        last: &quot;Howard&quot;,\n        aa: &quot;ab&quot;,\n        kk: &quot;zz&quot;\n    },\n    {\n        first: &quot;Joe&quot;,\n        last: &quot;DeRita&quot;,\n        aa: &quot;ab&quot;,\n        kk: &quot;bb&quot;\n    },\n    {\n        first: &quot;Joe&quot;,\n        last: &quot;DeRita&quot;,\n        aa: &quot;ab&quot;,\n        kk: &quot;vv&quot;\n    },\n    {\n        first: &quot;Joe&quot;,\n        last: &quot;DeRita&quot;,\n        aa: &quot;cc&quot;,\n        kk: &quot;aa&quot;\n    },\n    {\n        first: &quot;Joe&quot;,\n        last: &quot;Ab&quot;,\n        aa: &quot;ab&quot;,\n        kk: &quot;cc&quot;\n    }\n];\n\nconst CompareArray001 = function(array) {\n\n    var by = function(name) {\n\n        var that = function(a, b) {\n            try {\n\n                if (!a || !b || typeof a !== &quot;object&quot; || typeof b !== &quot;object&quot;) {\n\n                    throw {\n                        name: &quot;Error&quot;,\n                        message: &quot;\u30d7\u30ed\u30d1\u30c6\u30a3\u540d\u306b&quot; + name + &quot;\u3092\u6301\u3064\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u5fc5\u8981\u3067\u3059\u3002typeof a =&quot; + typeof a + &quot;, a = &quot; + a + &quot;, typeof b =&quot; + typeof b + &quot;, b = &quot; + b\n                    };\n\n                } else {\n\n                    const valueA = a[name];\n                    const valueB = b[name];\n\n                    if (valueA === valueB) {\n                        return 0;\n                    } else if (typeof valueA === typeof valueB) {\n                        return valueA &lt; valueB ? -1 : 1;\n                    } else {\n                        return typeof valueA &lt; typeof valueB ? -1 : 1;\n                    }\n                }\n\n            } catch (e) {\n                console.error(e.name + &quot;:&quot; + e.message);\n            }\n\n        };\n\n        return that;\n    };\n\n    return by(&quot;first&quot;)\n\n};\n\nconsole.log(&quot;--\u5143\u306e\u914d\u5217--&quot;);\ns.forEach(function(value, index, array) {\n    console.log(&quot;first = &quot; + s[index].first + &quot;, last = &quot; + s[index].last + &quot;, aa = &quot; + s[index].aa + &quot;, kk = &quot; + s[index].kk);\n})\n\nconsole.log(&quot;--sort\u5f8c\u306e\u914d\u5217--&quot;);\n\/\/CompareArray001\u95a2\u6570\u3067\u4e26\u3073\u66ff\u3048\u308b\u3002\n\/\/first\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u308b\u3002\ns.sort(CompareArray001(&quot;first&quot;)).forEach(function(value, index, array) {\n    console.log(&quot;first = &quot; + s[index].first + &quot;, last = &quot; + s[index].last + &quot;, aa = &quot; + s[index].aa + &quot;, kk = &quot; + s[index].kk);\n})\n\n\/*\n--\u5143\u306e\u914d\u5217-- \nfirst = Joe, last = DeRita, aa = zz, kk = wq \nfirst = ZCurly, last = Howard, aa = ab, kk = bb \nfirst = ACurly, last = Howard, aa = ab, kk = aa \nfirst = Joe, last = DeRita, aa = ab, kk = zz \nfirst = Moe, last = Howard, aa = ab, kk = aa \nfirst = Joe, last = Besser, aa = ab, kk = aa \nfirst = Shemp, last = Howard, aa = ab, kk = aa \nfirst = Larry, last = Fine, aa = ab, kk = aa \nfirst = Curly, last = Howard, aa = ab, kk = aa \nfirst = BCurly, last = Howard, aa = ab, kk = zz \nfirst = Joe, last = DeRita, aa = ab, kk = bb \nfirst = Joe, last = DeRita, aa = ab, kk = vv \nfirst = Joe, last = DeRita, aa = cc, kk = aa \nfirst = Joe, last = Ab, aa = ab, kk = cc \n--sort\u5f8c\u306e\u914d\u5217-- \nfirst = ACurly, last = Howard, aa = ab, kk = aa \nfirst = BCurly, last = Howard, aa = ab, kk = zz \nfirst = Curly, last = Howard, aa = ab, kk = aa \nfirst = Joe, last = DeRita, aa = zz, kk = wq \nfirst = Joe, last = DeRita, aa = ab, kk = zz \nfirst = Joe, last = Besser, aa = ab, kk = aa \nfirst = Joe, last = DeRita, aa = ab, kk = bb \nfirst = Joe, last = DeRita, aa = ab, kk = vv \nfirst = Joe, last = DeRita, aa = cc, kk = aa \nfirst = Joe, last = Ab, aa = ab, kk = cc \nfirst = Larry, last = Fine, aa = ab, kk = aa \nfirst = Moe, last = Howard, aa = ab, kk = aa \nfirst = Shemp, last = Howard, aa = ab, kk = aa \nfirst = ZCurly, last = Howard, aa = ab, kk = bb\n*\/\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">first\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u3001first\u304c\u540c\u3058\u5024\u306a\u3089\u3070last\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u308b\u3002<br>\u6bd4\u8f03\u95a2\u6570CompareArray001\u3092\u6539\u9020\u3057\u305f\u6bd4\u8f03\u95a2\u6570CompareArray002\u306f\u6b21\u306e\u901a\u308a\u3002<\/p>\n\n\n\n<pre><code>\nconst CompareArray002 = function(x, y) {\n\n    var by = function(name, minor) {\n\n        var that = function(a, b) {\n\n            try {\n\n                if (!a || !b || typeof a !== &quot;object&quot; || typeof b !== &quot;object&quot;) {\n\n                    throw {\n                        name: &quot;Error&quot;,\n                        message: &quot;\u30d7\u30ed\u30d1\u30c6\u30a3\u540d\u306b&quot; + name + &quot;\u3092\u6301\u3064\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u5fc5\u8981\u3067\u3059\u3002typeof a =&quot; + typeof a + &quot;, a = &quot; + a + &quot;, typeof b =&quot; + typeof b + &quot;, b = &quot; + b\n                    };\n\n                } else {\n\n                    const valueA = a[name];\n                    const valueB = b[name];\n\n                    if (valueA === valueB) {\n                        return typeof minor === &quot;function&quot; ? minor(a, b) : 0;\n                    } else if (typeof valueA === typeof valueB) {\n                        return valueA &lt; valueB ? -1 : 1;\n                    } else {\n                        return typeof valueA &lt; typeof valueB ? -1 : 1;\n                    }\n\n                }\n\n            } catch (e) {\n                console.error(e.name + &quot;:&quot; + e.message);\n            }\n\n        };\n\n        return that;\n\n    };\n\n    return by(x, by(y))\n\n};\n\nconsole.log(&quot;--sort\u5f8c\u306e\u914d\u5217--&quot;);\n\/\/CompareArray002\u95a2\u6570\u3067\u4e26\u3073\u66ff\u3048\u308b\u3002\n\/\/first\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u3001first\u304c\u540c\u3058\u5024\u306a\u3089\u3070last\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u308b\u3002\ns.sort(CompareArray002(&quot;first&quot;, &quot;last&quot;)).forEach(function(value, index, array) {\n    console.log(&quot;first = &quot; + s[index].first + &quot;, last = &quot; + s[index].last + &quot;, aa = &quot; + s[index].aa + &quot;, kk = &quot; + s[index].kk);\n})\n\n\/*\n--\u5143\u306e\u914d\u5217-- \nfirst = Joe, last = DeRita, aa = zz, kk = wq \nfirst = ZCurly, last = Howard, aa = ab, kk = bb \nfirst = ACurly, last = Howard, aa = ab, kk = aa \nfirst = Joe, last = DeRita, aa = ab, kk = zz \nfirst = Moe, last = Howard, aa = ab, kk = aa \nfirst = Joe, last = Besser, aa = ab, kk = aa \nfirst = Shemp, last = Howard, aa = ab, kk = aa \nfirst = Larry, last = Fine, aa = ab, kk = aa \nfirst = Curly, last = Howard, aa = ab, kk = aa \nfirst = BCurly, last = Howard, aa = ab, kk = zz \nfirst = Joe, last = DeRita, aa = ab, kk = bb \nfirst = Joe, last = DeRita, aa = ab, kk = vv \nfirst = Joe, last = DeRita, aa = cc, kk = aa \nfirst = Joe, last = Ab, aa = ab, kk = cc \n--sort\u5f8c\u306e\u914d\u5217-- \nfirst = ACurly, last = Howard, aa = ab, kk = aa \nfirst = BCurly, last = Howard, aa = ab, kk = zz \nfirst = Curly, last = Howard, aa = ab, kk = aa \nfirst = Joe, last = Ab, aa = ab, kk = cc \nfirst = Joe, last = Besser, aa = ab, kk = aa \nfirst = Joe, last = DeRita, aa = zz, kk = wq \nfirst = Joe, last = DeRita, aa = ab, kk = zz \nfirst = Joe, last = DeRita, aa = ab, kk = bb \nfirst = Joe, last = DeRita, aa = ab, kk = vv \nfirst = Joe, last = DeRita, aa = cc, kk = aa \nfirst = Larry, last = Fine, aa = ab, kk = aa \nfirst = Moe, last = Howard, aa = ab, kk = aa \nfirst = Shemp, last = Howard, aa = ab, kk = aa \nfirst = ZCurly, last = Howard, aa = ab, kk = bb\n*\/\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><br>first\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u3001first\u304c\u540c\u3058\u5024\u306a\u3089\u3070last\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u3001last\u304c\u540c\u3058\u5024\u306a\u3089\u3070aa\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u3001aa\u304c\u540c\u3058\u5024\u306a\u3089\u3070kk\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u308b\u3002<br>\u3053\u306e\u6539\u9020\u306b\u3088\u308a\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u304c\u4f55\u500b\u3042\u3063\u3066\u3082\u5bfe\u5fdc\u53ef\u80fd\u3068\u306a\u308b\u3002<br>\u6bd4\u8f03\u95a2\u6570CompareArray002\u3092\u6539\u9020\u3057\u305f\u6bd4\u8f03\u95a2\u6570CompareArray003\u306f\u6b21\u306e\u901a\u308a\u3002<\/p>\n\n\n\n<pre><code>\n\nconst CompareArray003 = function(array) {\n\n    const by = function(t) {\n\n        const name = t.name;\n        const minor = t.minor;\n\n        const that = function(a, b, i) {\n\n            try {\n\n                if (!a || !b || typeof a !== &quot;object&quot; || typeof b !== &quot;object&quot;) {\n\n                    throw {\n                        name: &quot;Error&quot;,\n                        message: &quot;\u30d7\u30ed\u30d1\u30c6\u30a3\u540d\u306b&quot; + name + &quot;\u3092\u6301\u3064\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u5fc5\u8981\u3067\u3059\u3002typeof a =&quot; + typeof a + &quot;, a = &quot; + a + &quot;, typeof b =&quot; + typeof b + &quot;, b = &quot; + b\n                    };\n\n                } else {\n\n                    if (typeof i === &quot;undefined&quot;) {\n                        i = 0;\n                    }\n\n                    const valueA = a[name[i]];\n                    const valueB = b[name[i]];\n\n                    if (valueA === valueB) {\n                        return typeof minor === &quot;function&quot; ? minor(a, b, i + 1) : 0;\n                    } else if (typeof valueA === typeof valueB) {\n                        return valueA &lt; valueB ? -1 : 1;\n                    } else {\n                        return typeof valueA &lt; typeof valueB ? -1 : 1;\n                    }\n\n                }\n\n            } catch (e) {\n                console.error(e.name + &quot;:&quot; + e.message);\n            }\n\n        };\n\n        return that;\n\n    };\n\n    \/\/first\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u308b\u3002\n    \/\/return by({&quot;name&quot;: array,&quot;minor&quot;: null});\n    \/\/first\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u3001first\u304c\u540c\u3058\u5024\u306a\u3089\u3070last\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u308b\u3002\n    \/\/return by({&quot;name&quot;: array,&quot;minor&quot;: by({&quot;name&quot;: array,&quot;minor&quot;: null})});\n    \/\/first\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u3001first\u304c\u540c\u3058\u5024\u306a\u3089\u3070last\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u3001last\u304c\u540c\u3058\u5024\u306a\u3089\u3070aa\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u308b\u3002\n    \/\/return by({&quot;name&quot;: array,&quot;minor&quot;: by({&quot;name&quot;: array,&quot;minor&quot;: by({&quot;name&quot;: array,&quot;minor&quot;: null})})});\n    \/\/first\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u3001first\u304c\u540c\u3058\u5024\u306a\u3089\u3070last\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u3001last\u304c\u540c\u3058\u5024\u306a\u3089\u3070aa\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u3001aa\u304c\u540c\u3058\u5024\u306a\u3089\u3070kk\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u308b\u3002\n    return by({&quot;name&quot;: array,&quot;minor&quot;: by({&quot;name&quot;: array,&quot;minor&quot;: by({&quot;name&quot;: array,&quot;minor&quot;: by({&quot;name&quot;: array,&quot;minor&quot;: null})})})});\n};\n\nconsole.log(&quot;--sort\u5f8c\u306e\u914d\u5217--&quot;);\n\/\/CompareArray003\u95a2\u6570\u3067\u4e26\u3073\u66ff\u3048\u308b\u3002\n\/\/first\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u3001first\u304c\u540c\u3058\u5024\u306a\u3089\u3070last\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u3001last\u304c\u540c\u3058\u5024\u306a\u3089\u3070aa\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u3001aa\u304c\u540c\u3058\u5024\u306a\u3089\u3070kk\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u308b\u3002\ns.sort(CompareArray003([&quot;first&quot;, &quot;last&quot;, &quot;aa&quot;, &quot;kk&quot;])).forEach(function(value, index, array) {\n    console.log(&quot;first = &quot; + s[index].first + &quot;, last = &quot; + s[index].last + &quot;, aa = &quot; + s[index].aa + &quot;, kk = &quot; + s[index].kk);\n})\n\n\/*\n--\u5143\u306e\u914d\u5217-- \nfirst = Joe, last = DeRita, aa = zz, kk = wq \nfirst = ZCurly, last = Howard, aa = ab, kk = bb \nfirst = ACurly, last = Howard, aa = ab, kk = aa \nfirst = Joe, last = DeRita, aa = ab, kk = zz \nfirst = Moe, last = Howard, aa = ab, kk = aa \nfirst = Joe, last = Besser, aa = ab, kk = aa \nfirst = Shemp, last = Howard, aa = ab, kk = aa \nfirst = Larry, last = Fine, aa = ab, kk = aa \nfirst = Curly, last = Howard, aa = ab, kk = aa \nfirst = BCurly, last = Howard, aa = ab, kk = zz \nfirst = Joe, last = DeRita, aa = ab, kk = bb \nfirst = Joe, last = DeRita, aa = ab, kk = vv \nfirst = Joe, last = DeRita, aa = cc, kk = aa \nfirst = Joe, last = Ab, aa = ab, kk = cc \n--sort\u5f8c\u306e\u914d\u5217-- \nfirst = ACurly, last = Howard, aa = ab, kk = aa \nfirst = BCurly, last = Howard, aa = ab, kk = zz \nfirst = Curly, last = Howard, aa = ab, kk = aa \nfirst = Joe, last = Ab, aa = ab, kk = cc \nfirst = Joe, last = Besser, aa = ab, kk = aa \nfirst = Joe, last = DeRita, aa = ab, kk = bb \nfirst = Joe, last = DeRita, aa = ab, kk = vv \nfirst = Joe, last = DeRita, aa = ab, kk = zz \nfirst = Joe, last = DeRita, aa = cc, kk = aa \nfirst = Joe, last = DeRita, aa = zz, kk = wq \nfirst = Larry, last = Fine, aa = ab, kk = aa \nfirst = Moe, last = Howard, aa = ab, kk = aa \nfirst = Shemp, last = Howard, aa = ab, kk = aa \nfirst = ZCurly, last = Howard, aa = ab, kk = bb\n*\/\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">first\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u3001first\u304c\u540c\u3058\u5024\u306a\u3089\u3070last\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u3001last\u304c\u540c\u3058\u5024\u306a\u3089\u3070aa\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u3001aa\u304c\u540c\u3058\u5024\u306a\u3089\u3070kk\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u308b\u3002<br>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u8ffd\u52a0\u3059\u308b\u3068\u6bd4\u8f03\u95a2\u6570CompareArray003\u3092\u4fee\u6b63\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u306e\u3067\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u8ffd\u52a0\u3057\u3066\u3082\u6bd4\u8f03\u95a2\u6570CompareArray003\u3092\u4fee\u6b63\u4e0d\u8981\u306b\u306a\u308b\u3088\u3046\u306b\u518d\u5e30\u95a2\u6570\u3092\u4f7f\u7528\u3059\u308b\u3088\u3046\u306b\u6539\u9020\u3059\u308b\u3002<br>\u6bd4\u8f03\u95a2\u6570CompareArray003\u3092\u6539\u9020\u3057\u305f\u6bd4\u8f03\u95a2\u6570CompareArray004\u306f\u6b21\u306e\u901a\u308a\u3002<br>\u6bd4\u8f03\u95a2\u6570CompareArray004\u306f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u304c\u5897\u3048\u305f\u5834\u5408\u306f\u3001\u6bd4\u8f03\u95a2\u6570CompareArray004\u306e\u5f15\u6570\u306e\u914d\u5217\u306e\u8981\u7d20\u306b\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u8ffd\u52a0\u3059\u308c\u3070\u3001\u8ffd\u52a0\u3057\u305f\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u5024\u3067\u30bd\u30fc\u30c8\u304c\u53ef\u80fd\u306b\u306a\u308b\u3002<\/p>\n\n\n\n<pre><code>\nconst CompareArray004 = function(array) {\n\n    const by = function(t) {\n\n        const name = t.name;\n        const minor = t.minor;\n\n        const that = function(a, b, i) {\n\n            try {\n\n                if (!a || !b || typeof a !== &quot;object&quot; || typeof b !== &quot;object&quot;) {\n\n                    throw {\n                        name: &quot;Error&quot;,\n                        message: &quot;\u30d7\u30ed\u30d1\u30c6\u30a3\u540d\u306b&quot; + name + &quot;\u3092\u6301\u3064\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u5fc5\u8981\u3067\u3059\u3002typeof a =&quot; + typeof a + &quot;, a = &quot; + a + &quot;, typeof b =&quot; + typeof b + &quot;, b = &quot; + b\n                    };\n\n                } else {\n\n                    if (typeof i === &quot;undefined&quot;) {\n                        i = 0;\n                    }\n\n                    const valueA = a[name[i]];\n                    const valueB = b[name[i]];\n\n                    if (valueA === valueB) {\n                        return typeof minor === &quot;function&quot; ? minor(a, b, i + 1) : 0;\n                    } else if (typeof valueA === typeof valueB) {\n                        return valueA &lt; valueB ? -1 : 1;\n                    } else {\n                        return typeof valueA &lt; typeof valueB ? -1 : 1;\n                    }\n\n                }\n\n            } catch (e) {\n                console.error(e.name + &quot;:&quot; + e.message);\n            }\n\n        };\n\n        return that;\n\n    };\n\n    const fnc = function(t, array) {\n        \/\/\u518d\u5e30\u95a2\u6570\u3092\u4f7f\u3046\n        const innerFnc = function(u) {\n            return u === 0 ? by({\n                &quot;name&quot;: array,\n                &quot;minor&quot;: null\n            }) : by({\n                &quot;name&quot;: array,\n                &quot;minor&quot;: innerFnc(u - 1)\n            });\n        };\n        return innerFnc(t);\n    };\n\n    return fnc(array.length - 1, array);\n};\n\nconsole.log(&quot;--sort\u5f8c\u306e\u914d\u5217--&quot;);\n\/\/CompareArray004\u95a2\u6570\u3067\u4e26\u3073\u66ff\u3048\u308b\u3002\n\/\/first\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u3001first\u304c\u540c\u3058\u5024\u306a\u3089\u3070last\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u3001last\u304c\u540c\u3058\u5024\u306a\u3089\u3070aa\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u3001aa\u304c\u540c\u3058\u5024\u306a\u3089\u3070kk\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u308b\u3002\n\/\/\u518d\u5e30\u95a2\u6570\u3092\u4f7f\u7528\u3059\u308b\u3002\ns.sort(CompareArray004([&quot;first&quot;, &quot;last&quot;, &quot;aa&quot;,&quot;kk&quot;])).forEach(function(value, index, array) {\n    console.log(&quot;first = &quot; + s[index].first + &quot;, last = &quot; + s[index].last + &quot;, aa = &quot; + s[index].aa + &quot;, kk = &quot; + s[index].kk);\n})\n\n\/*\n--\u5143\u306e\u914d\u5217-- \nfirst = Joe, last = DeRita, aa = zz, kk = wq \nfirst = ZCurly, last = Howard, aa = ab, kk = bb \nfirst = ACurly, last = Howard, aa = ab, kk = aa \nfirst = Joe, last = DeRita, aa = ab, kk = zz \nfirst = Moe, last = Howard, aa = ab, kk = aa \nfirst = Joe, last = Besser, aa = ab, kk = aa \nfirst = Shemp, last = Howard, aa = ab, kk = aa \nfirst = Larry, last = Fine, aa = ab, kk = aa \nfirst = Curly, last = Howard, aa = ab, kk = aa \nfirst = BCurly, last = Howard, aa = ab, kk = zz \nfirst = Joe, last = DeRita, aa = ab, kk = bb \nfirst = Joe, last = DeRita, aa = ab, kk = vv \nfirst = Joe, last = DeRita, aa = cc, kk = aa \nfirst = Joe, last = Ab, aa = ab, kk = cc \n--sort\u5f8c\u306e\u914d\u5217-- \nfirst = ACurly, last = Howard, aa = ab, kk = aa \nfirst = BCurly, last = Howard, aa = ab, kk = zz \nfirst = Curly, last = Howard, aa = ab, kk = aa \nfirst = Joe, last = Ab, aa = ab, kk = cc \nfirst = Joe, last = Besser, aa = ab, kk = aa \nfirst = Joe, last = DeRita, aa = ab, kk = bb \nfirst = Joe, last = DeRita, aa = ab, kk = vv \nfirst = Joe, last = DeRita, aa = ab, kk = zz \nfirst = Joe, last = DeRita, aa = cc, kk = aa \nfirst = Joe, last = DeRita, aa = zz, kk = wq \nfirst = Larry, last = Fine, aa = ab, kk = aa \nfirst = Moe, last = Howard, aa = ab, kk = aa \nfirst = Shemp, last = Howard, aa = ab, kk = aa \nfirst = ZCurly, last = Howard, aa = ab, kk = bb\n*\/\n\n<\/code><\/pre>\n\n\n\n<script type=\"text\/javascript\">\njQuery(function($){\n$(\".jp-video\").hide();\n});\n<\/script>\n\n\n\n<p class=\"wp-block-paragraph\"><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>sort\u3092\u4f7f\u3063\u3066\u914d\u5217\u3092\u4e26\u3073\u66ff\u3048\u308b\u3002\u914d\u5217\u306e\u8981\u7d20\u304c\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u5834\u5408\u306esort\u3092\u8003\u3048\u308b\u3002\u914d\u5217s\u306e\u8981\u7d20\u304c\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u5834\u5408\u306b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u540d\u300cfirst\u300d\u306e\u5024\u3067\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u308b\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-2722","post","type-post","status-publish","format-standard","hentry","category-javascript"],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/attacktube.com\/index.php?rest_route=\/wp\/v2\/posts\/2722","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/attacktube.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/attacktube.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/attacktube.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/attacktube.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2722"}],"version-history":[{"count":23,"href":"https:\/\/attacktube.com\/index.php?rest_route=\/wp\/v2\/posts\/2722\/revisions"}],"predecessor-version":[{"id":2804,"href":"https:\/\/attacktube.com\/index.php?rest_route=\/wp\/v2\/posts\/2722\/revisions\/2804"}],"wp:attachment":[{"href":"https:\/\/attacktube.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2722"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/attacktube.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2722"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/attacktube.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2722"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}