DEV Community

Jan Küster 🔥
Jan Küster 🔥

Posted on

1

One-Liner Puzzle - Fill Array with indices

Premise

Write a function f, that receives an integer n and returns a new Array of size n and which contains in each entry the index i. For example:

f(0) => []
f(3) => [0, 1, 2]
f(5) => [0, 1, 2, 3, 4]

Constraints

  • all code in one line
  • max allowed bytes/characters is 36
  • no underscore/lodash/libraries, just vanilla JS
  • ES6 is recommended
  • assume all inputs of n to be greater or equal 0 and lower than Number.MAX_SAFE_INTEGER
  • no performance considerations for this puzzle

Spoiler alert

If you like to solve on your own, please avoid the comment section until you solved it or (hopefully not) give up.

Hints

  • you should not target for "clean" code
  • omit variable declarations
  • remove any whitespace where you can
  • start with a working implementation and narrow down
  • if you are totally new to this appraoch, try my introduction to one-liners

Have fun!

SurveyJS custom survey software

Simplify data collection in your JS app with a fully integrated form management platform. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more. Integrates with any backend system, giving you full control over your data and no user limits.

Learn more

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay