Passionate about the AI ecosystem. I love building AI tools that make developers more productive. Writing about software engineering, AI, and the things that keep bugging me at debuggr.io
Passionate about the AI ecosystem. I love building AI tools that make developers more productive. Writing about software engineering, AI, and the things that keep bugging me at debuggr.io
Passionate about the AI ecosystem. I love building AI tools that make developers more productive. Writing about software engineering, AI, and the things that keep bugging me at debuggr.io
This challenge was simple, so here's a brainfuck solution too. Only works with characters 1-9 as inputs (I have an idea for reading multidigit numbers as input, but I'm on my phone and don't want to type it out).
JavaScript:
That creates an Array from 0 to n not from 1 to n ;-)
const spreadNumber = n => Array(n).fill(0).map((_, i) => i+1);Yeah, i didnt notice its not zero based
I think you have an off-by-one error:
spreadNumber(2)gives[0, 1]instead of[1, 2]. Nice and concise, though!Thanks. I didnt notice its zero based
Another way:
Haskell, many ways
This challenge was simple, so here's a brainfuck solution too. Only works with characters 1-9 as inputs (I have an idea for reading multidigit numbers as input, but I'm on my phone and don't want to type it out).
Python
this will not work, it doesn't include the last digit:
spreadNumber(4)=>[1, 2, 3]you forgot to add
+1onnYou are right, I didnt take that in consideration, but it just range(1,n+1)
Javascript, just using a for loop
Codepen
Clojure short and simple
and some tests...
Late to the party, as always.
Example:
dart
lol damn, while this is one way, looking at other solutions. I forgot range was a thing.
Python
Python, shortest approach
you could've use just
rangelike this:Simple JS
Haskell
The easiest challenge yet.
Ruby solution below. We could also return a Range directly, but here I'm being purist with the exercise.
Elixir
Javascript
Zero based ;)
Elm
C++
Rust
Playground
GO