2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

10分間隔で 10時〜23時台の配列をつくる

Last updated at Posted at 2018-12-18

こういう配列がほしい

["10:00",
 "10:10",
 "10:20",
 "10:30",
...
...
 "23:30",
 "23:40",
 "23:50"]

どうやってやる?

interval = 10;
[*10..23].product(0.step(60 - interval, interval).map{|n| n.to_s.rjust(2, '0')}).map{|hour, min| "#{hour}:#{min}"}

これでいけた。
interval の値を変えれば、任意の分間隔での配列作れるはず。

なんか

もっと cool なやり方あったら教えてくれよな :wink:

2
0
2

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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?