Numbers to Arrays and Vice Versa

Published by Helen Yu in

Write two functions:

  1. to_array(), which converts a number to an array of its digits.
  2. to_number(), which converts an array of digits back to its number.

Examples

to_array(235) ➞ [2, 3, 5]

to_array(0) ➞ [0]

to_number([2, 3, 5]) ➞ 235

to_number([0]) ➞ 0

Notes

All test cases will be weakly positive numbers: >= 0

Watch a quick demo on how Edabit works.