From 69b3e2b97fa775cfae4e35462303e3e7b7856c59 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Thu, 14 Dec 2017 22:53:42 +0200 Subject: [PATCH] Update number-to-array-of-digits.md --- snippets/number-to-array-of-digits.md | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/snippets/number-to-array-of-digits.md b/snippets/number-to-array-of-digits.md index 9493c279f..f00a62b75 100644 --- a/snippets/number-to-array-of-digits.md +++ b/snippets/number-to-array-of-digits.md @@ -1,14 +1,9 @@ ### Number to array of digits -Convert the number to a string, split the string using `split()`. -use `parseInt()` to convert every element back to integer. +Convert the number to a string, use `split()` to convert build an array. +Use `Array.map()` and `parseInt()` to transform each value to an integer. ```js -const num2array = (n) =>{ - return (''+n).split('').map((i) =>{ - return parseInt(i); - }) -} - -// num2array(2334) -> [2, 3, 3, 4] -``` \ No newline at end of file +const digitize = n => (''+n).split('').map(i => parseInt(i)); +// digitize(2334) -> [2, 3, 3, 4] +```