Kevin Del Castillo Ramirez (JS Challenges) #33
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I noticed that there are some incorrect unit tests for
ownPower
anddigitSum
. For the former the last test is failing (i.e.ownPower(21, 12)
) because21 ** 21
is larger thanNumber.MAX_SAFE_INTEGER
this already creates an overflow, if you don't use aBigInt
from the beginning final sum is obviously going to be bigger thanNumber.MAX_SAFE_INTEGER
, and for the latter something similar was happening, take for example the factorial of 42, this number is also going to be greater thanNumber.MAX_SAFE_INTEGER
usingnumber
here is incorrect because it's going to produce an overflow.Python interpreter:
To prove these points I included a Python3 script (
challenge.py
) with implementations to those two functions, but with the difference that Python3 supports arbitrarily large numbers out of the box, if you run this script you'll see the correct values.