question for Sunday vibes | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

question for Sunday vibes

Given a non-negative integer, return an array or a list of the individual digits in order. Specification digitize(n) separate multiple digit numbers into an array Parameters n: Number - Number to be converted Return Value Array<Number> - Array of separated single digit integers Examples n Return Value 123 [1,2,3] 8675309 [8,6,7,5,3,0,9]

7th Oct 2018, 11:14 AM
ohwo oghenekaro
ohwo oghenekaro - avatar
2 Answers
+ 1
ohwo oghenekaro just do: const digitize = (n) => { r = n.toString().split(''); r.forEach((el, i, a) => { a[i] = parseInt(el); }) return r } digitize(123) // [1, 2, 3]
7th Oct 2018, 11:56 AM
Ulisses Cruz
Ulisses Cruz - avatar
+ 1
ohwo oghenekaro, In additional to Ulisses Cruz's answer: It is maybe not required but here is also an snippet that removes all duplicates👍 var n = Number(1234554321), rep = n.toString().split(""), len = rep.length, arr = []; for (let i=0; i<len; i++){ if (arr.indexOf(rep[i]) == -1){ arr.push(rep[i]); } } console.log(arr);
7th Oct 2018, 1:56 PM
🌴Vincent Berger🌴
🌴Vincent Berger🌴 - avatar