Setup
Implement a function that will create an array and fill it with numbers ranging from 1
to n
. The numbers will always be positive.
Examples
spreadNumber(1)
=> [1]
spreadNumber(2)
=> [1, 2]
spreadNumber(5)
=> [1, 2, 3, 4, 5]
Tests
spreadNumber(3)
spreadNumber(6)
spreadNumber(9)
Good luck!
This challenge comes from linisnie on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Latest comments (27)
Javascript
Zero based ;)
Elixir
Simple JS
Late to the party, as always.
Example:
Clojure short and simple
and some tests...
Javascript, just using a for loop
Codepen
GO
Rust
Playground
dart
lol damn, while this is one way, looking at other solutions. I forgot range was a thing.
C++