hkt-toolbelt
Version:
Functional and composable type utilities
25 lines (24 loc) • 554 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.toList = void 0;
/**
* Given a number, convert it to a list of digits.
*
* @param {number} x - The number to convert to a list of digits.
*
* @example
* ```ts
* import { NaturalNumber } from "hkt-toolbelt";
*
* const result = NaturalNumber.toList(42)
* // ^? ['4', '2']
* ```
*/
exports.toList = ((x) => {
const digits = [];
while (x > 0) {
digits.push(`${x % 10}`);
x = Math.floor(x / 10);
}
return digits.reverse();
});