← Back to challenges

Number Split

JavaScriptHardnumbersarraysmath

Instructions

Given a number, return an array containing the two halves of the number. If the number is odd, make the rightmost number higher.

Examples

numberSplit(4) ➞ [2, 2]

numberSplit(10) ➞ [5, 5]

numberSplit(11) ➞ [5, 6]

numberSplit(-9) ➞ [-5, -4]

Notes

  • All numbers will be integers.
  • You can expect negative numbers too.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Come Check Out This Crazy Function