+ 1

How to convert my output as a linked list

var addTwoNumbers = function(l1, l2) { let strL1=""; for(let i=l1.length-1;i>=0;i--){ strL1+=l1[i]; } let numL1=Number(strL1); let strL2=""; for(let i=l2.length-1;i>=0;i--){ strL2+=l2[i]; } let numL2=Number(strL2); let result = (numL1 + numL2).toString(); let rev=[]; for(let i=result.length-1;i>=0;i--){ rev.push(result[i]); } console.log(rev.map(Number));//How to convert it to linked list }; addTwoNumbers([9,9,9,9,9,9,9], [9,9,9,9]);

21st Jun 2022, 4:14 AM
TINKLE DASH
TINKLE DASH - avatar
5 odpowiedzi
21st Jun 2022, 8:01 AM
PanicS
PanicS - avatar
0
It's in array format
21st Jun 2022, 7:37 AM
TINKLE DASH
TINKLE DASH - avatar
0
How you output need to look like? Your output is [8, 9, 9, 9, 0, 0, 0, 1], but sololearn compile it as 8,9,9,9,0,0,0,1 If you test your code somewere else you will see normal array
21st Jun 2022, 7:59 AM
PanicS
PanicS - avatar