← Back to challenges

Making a Simple Dartboard

JavaScriptHardarraysnumbersloops

Instructions

Create a function which creates a square dartboard of side length n. The value of a number should increase, the closer it is to the centre of the board.

Examples

makeDartboard(3) ➞ [
  111,
  121,
  111
]

makeDartboard(8) ➞ [
  11111111,
  12222221,
  12333321,
  12344321,
  12344321,
  12333321,
  12222221,
  11111111
]

makeDartboard(5) ➞ [
  11111,
  12221,
  12321,
  12221,
  11111
]

Notes

If the size given is an even number, the centre should be made up of the 4 highest values.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.