LoginSignup
2
2

More than 5 years have passed since last update.

遅延評価的なJavaScript(ECMAScript2018)で全ての漢字や絵文字を取得する

Last updated at Posted at 2018-10-12

実際の遅延評価とは違うと思う(詳しく調べてないけど雰囲気はこれで合ってる、はず)ので詳しいひといたら参考になるURLとか書籍とか教えてもらえると助かります。

漢字

[...Array(10000000).keys()].map(function(value){
  return String.fromCharCode(value)
}).filter(function(value){
  return value.match(/[一-龠]/);
})

😇絵文字😇

[...Array(10000000).keys()].map(function(value){
  return String.fromCharCode(value)
}).filter(function(value){
  return /\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F/gu.test(value);
})

【参考】
https://stabucky.com/wp/archives/7594 →漢字の正規表現
https://stackoverflow.com/questions/31208058/loss-of-floating-point-precision-in-javascript-arrays-as-they-get-really-large/31208375 →maximum length of an Array is 4,294,967,295 とのことだがこの数で配列を作るとブラウザが止まった
https://blog.tes.co.jp/entry/2018/06/29/145450#Unicode%E3%81%AE%E6%96%87%E5%AD%97%E3%83%97%E3%83%AD%E3%83%91%E3%83%86%E3%82%A3 →ECMA script 2018の文字プロパティ

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2