LoginSignup
1
0

More than 1 year has passed since last update.

paiza.ioでelixir その96

Last updated at Posted at 2022-11-24

概要

paiza.ioでelixirやってみた。
練習問題やってみた。

練習問題

api叩いて、covid-19の県毎の人員を求めよ。

サンプルコード

:inets.start
:ssl.start
{:ok, {_status, _headers, body}} = :httpc.request('https://covid19-japan-web-api.vercel.app/api/v1/prefectures')
body = IO.iodata_to_binary(body)
Regex.scan(~r/name_ja\": \"(.+?)\",|population\": (.+?),/, body)
|> Enum.map(fn 
    [_, v] -> 
        IO.write(v)
        IO.write(" ")
    [_, _, v] -> 
        IO.puts(v)
end)

実行結果

北海道 5248552
青森 1246138
岩手 1226430
宮城 2303160
秋田 965968
山形 1077057
福島 1847950
茨城 2868041
栃木 1942312
群馬 1937626
埼玉 7337330
千葉 6279026
東京 13942856
神奈川 9200166
新潟 2222004
富山 1042998
石川 1137181
福井 767742
山梨 812056
長野 2049023
岐阜 1988931
静岡 3639226
愛知 7552873
三重 1779770
滋賀 1413959
京都 2583140
大阪 8823453
兵庫 5463609
奈良 1331330
和歌山 923721
鳥取 555663
島根 673891
岡山 1891346
広島 2807987
山口 1355495
徳島 728633
香川 956069
愛媛 1338811
高知 697674
福岡 5110113
佐賀 814211
長崎 1325205
熊本 1746740
大分 1134431
宮崎 1072077
鹿児島 1599984
沖縄 1454184

成果物

以上。

1
0
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
1
0