Prepare repository for merge

This commit is contained in:
Angelos Chalaris
2023-05-01 22:35:56 +03:00
parent fc4e61e6fa
commit b3ad01863a
578 changed files with 0 additions and 0 deletions

View File

@ -0,0 +1,22 @@
---
title: Digitize number
type: snippet
tags: [math]
cover: industrial-tokyo
dateModified: 2020-10-18T14:58:09+03:00
---
Converts a number to an array of digits, removing its sign if necessary.
- Use `Math.abs()` to strip the number's sign.
- Convert the number to a string, using the spread operator (`...`) to build an array.
- Use `Array.prototype.map()` and `parseInt()` to transform each value to an integer.
```js
const digitize = n => [...`${Math.abs(n)}`].map(i => parseInt(i));
```
```js
digitize(123); // [1, 2, 3]
digitize(-123); // [1, 2, 3]
```