GitHub 6219★

Get the arrays of digits from a number

JavaScript version

const digitize = (n) => `${n}`.split('').map((v) => parseInt(v, 10));

// Or
const digitize = (n) => [...`${n}`].map((v) => parseInt(v, 10));

TypeScript version

const digitize = (n: number): number[] => `${n}`.split('').map((v) => parseInt(v, 10));

// Or
const digitize = (n: number): number[] => [...`${n}`].map((v) => parseInt(v, 10));

Examples

digitize(123); // [1, 2, 3]
Follow me on and to get more useful contents.