Create array of n items based on integer value

ruby

Solution

You can just splat a range:

[*1..10]
#=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Ruby 1.9 allows multiple splats, which is rather handy:

[*1..3, *?a..?c]
#=> [1, 2, 3, "a", "b", "c"]

Problem

Given I have an integer value of, e.g., `10`. How can I create an array of 10 elements like `[1,2,3,4,5,6,7,8,9,10]`?

Original source

Related problems