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.
Cases similar to
[1,0,1,0,-1,0,-1]
are rarely generated in random cases, allowing this kind of incorrect solutions to pass:I don't open an extra issue, but NodeJS version should be updated to 14.0 and the new framework with mocha should be used.
The case if the input contains NaN you should return -1 is just a sort of input validation that distracts from the task, doesn't make much sense and makes it hard to implement in some other languages. It should be removed.
Good question but what is the point in including zeros?
In order to make it more clear, I might specify that in case of finding a zero, we consider it a cross only if the previous and the next value are of opposite signs.
Ex.
[1,0,-1] Yes
[-1,0,1] Yes
[1,0,1] No
Nice kata though.
Eh, I don't think you can. But if you have to transform something anyway, type conversion or whatever, it does return a new array.
Oooh, I didn't know you could use
map
without a function. Thanks!Wasn't me. :]
.slice()
is another way to do it.Object.assign()
is yet another.Array.from()
,.map()
,.filter()
, all return new copies.You got it right! :]
If I've understood correctly, I've added an assertation to address this. Let me know if I haven't got it right!
I went to fix it, but someone has already. Awesome.
If you're passing
Object
s ( includingArray
s ) as arguments, you should make sure yourexpected
value does not depend on a value that may have been clobbered by the user function. Otherwise, this.Either call the reference solution first ( and make sure it does not modify its input! ), or pass user a copy of the randomly generated input.
([...signal])
instead of(signal)
works just fine.My latest solution ignores crossings via zero. But it passes.
I'd suggest a static test for that - you can't rely on
Math.random()
generating exactly0.5
so there is a0
in a random test.And they work. :]
Ten isn't much really; you have a better chance of catching bugs with a hundred or more. You have to chance upon some condition that causes a bug to manifest after all.
Now specified in the description 🙂
Should be fixed now!
Loading more items...