How to organize the conversion of a number to an array?