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.
I will lower the range to 32 bit in JS.
Try not to use floating point arithmetic.
Fix applied. Thanks @RileyHunter
Confirming this is a bug in the reference solution. When the first polynomial string ends with the variable and the second starts with it the variable is incorrectly detected as being multiple characters, e.g.
Testing: -1+4a and a-9a^3: expected '-36a^4+9a^3+4a^2-a' to equal '-NaN'
This is because it's scanning the concatenated string
-1+4aa-9a^3
and finding the "variable"aa
, then parsing breaks down from there. I've fixed this in a fork here:https://www.codewars.com/kumite/65383e33e681c41613bcb605?sel=65383e33e681c41613bcb605
Just waiting for approval
Thank you, your advices has a sense.
Foreach
here would be perfect choice.Reduce
is also an option, but as with amap
case, there will no further chaining afterreduce
, so it would be not so much neccessery.Solution with
map
+join
is also a good case, so we can get rid ofresult
variable. But in this case we additionally need to handle empty string scenario:return ......map().join('') || '';