0

I'm aware that this initial solution is very expensive, I just wanted to get the green before I tighten it up and start experimenting. When my solution failed a test on Leetcode, I put their parameter into my unit test and it passed. Any ideas why it works on my machine and not on their server?

function plusOne(digits) {
    let stringOfDigits = digits.reduce((str, int) => str + int, "")
    return Array.from(String(parseInt(stringOfDigits) + 1), Number)
}

Here's what I'm getting from Leetcode:

Input:
[6,1,4,5,3,9,0,1,9,5,1,8,6,7,0,5,5,4,3]
Output:
[6,1,4,5,3,9,0,1,9,5,1,8,6,7,0,5,0,0,0]
Expected:
[6,1,4,5,3,9,0,1,9,5,1,8,6,7,0,5,5,4,4]
  • 1
    Use a BigInt instead if you want that approach – CertainPerformance May 16 '22 at 03:22
  • `6145390195186705543` is larger than the maximum safe integer you can use in jS ... not sure why you think your unit test passed, it couldn't since it would always result in `[6,1,4,5,3,9,0,1,9,5,1,8,6,7,0,5,0,0,0]` on ANY JS engine anywhere – Bravo May 16 '22 at 03:24

0 Answers0