Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
2 > 1
You are sort of right, do not expect this one to be easy, I'm stuck on this for +5 days, and still a couple of final tests are failing
You have the correct idea about deep ( or maybe shallow, see above ) copies and mutating the array itself.
Documentation can tell you which methods work by mutation and which by returning a new value.
Mutating input values will mutate it at the called site as well as at the call site, which is dangerous in general and will explicitly fail you in this kata.
Look into the difference between "pure code" and "programming by side effect". Impure code is the source of a lot of very preventable bugs.
This comment is hidden because it contains spoiler information about the solution
I don't know Java ( at all. but I had just seen the term "arrayList" in a Java context ), and I don't understand exactly what your problem is. I'd love to help you, but "I don't understand the mechanism" doesn't tell me what you are not understanding.
JavaScript is not Java. JS does not have Lists or ArrayLists. JS Arrays are fully dynamic; there is no size limit at any time ( apart from a general maximum size of ridiculous ).
array methods such as
indexOf()
are not magical, they use loops behind the scenes. you have to take into account how library functions work when you reason about your code's space and time complexity.Check the hint at the bottom:
There are two problems with your solution:
n = 30
,30!
has 32 digits but JavaScript'sNumber
can hold ~16 digits at most. When your values get larger than 16 digits, the least significant digits are lost and you cannot use them reliably for this problem.n
can go up to1_000_000_000
. Calculating1_000_000_000!
will take forever, and your naive solution will not work because it will be too slow, and will eat up whole available memory.You need to find some better approach than calculating the exact value of the factorial.
This is an old kata, running an old version of NodeJS. At some point it'll probably get upgraded; until then, roll your own
.flat
because it is unsupported.All arrays are objects in JS.