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).
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
Frontend Tech Lead, 15+ years. I structure large React/TypeScript monorepos so many teams can ship fast. Building IsoLoop, an open-source event-loop isolation runtime for web apps.
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).
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
Another way:
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
dart
lol damn, while this is one way, looking at other solutions. I forgot range was a thing.
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:
Elixir
Haskell
The easiest challenge yet.
Python
Ruby solution below. We could also return a Range directly, but here I'm being purist with the exercise.
Simple JS
Python, shortest approach
you could've use just
rangelike this:Javascript
Zero based ;)
C++
Rust
Playground
GO