5
1

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.

jsでrange関数(min, max, step)

Last updated at Posted at 2018-04-20

jsでrange関数をつくる - Qiita

これにmin引数とstep引数が欲しくなった。こういうやつである。

range(0, 10, 2);
// [0, 2, 4, 6, 8]

コメントで教えていただいた。これで実現できる。

const range = (min, max, step=1) =>
    Array.from({length: (max - min + step) / step}, (v, k) => min + k*step)

firefox59で動作確認した。

5
1
4

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?