<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>panda_noir</author_name>
  <author_url>https://blog.hatena.ne.jp/panda_noir/</author_url>
  <blog_title>Panda Noir</blog_title>
  <blog_url>https://www.pandanoir.info/</blog_url>
  <categories>
    <anon>アルゴリズム</anon>
  </categories>
  <description>世の中には辞書順という便利なものがあります。しかし、意外とオリジナルの順序を作りソートするプログラムは見かけません。 例えば麻雀では「東」「南」「西」「北」という4つの牌があります。これら4種類のみからなる配列を「東南西北」という順にソートすることを考えます。 結論はこうです。 const arr = ['東', '西', '東', '北', '西', '南']; arr.sort((a, b) =&gt; { return '東南西北'.indexOf(a) -'東南西北'.indexOf(b); }); // arr: [&quot;東&quot;, &quot;東&quot;, &quot;南&quot;, &quot;西&quot;, &quot;西&quot;, &quot;北&quot;] 「4種類のみか…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fwww.pandanoir.info%2Fentry%2F2016%2F03%2F31%2F154408&quot; title=&quot;好きな順番で配列をソートする - Panda Noir&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url></image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2016-03-31 15:44:08</published>
  <title>好きな順番で配列をソートする</title>
  <type>rich</type>
  <url>https://www.pandanoir.info/entry/2016/03/31/154408</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
