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.
Is there any difference between importing the library first opposed to doing Math.abs() ?
It is not best practice. The same people that go on leetcode that demands more of them and then downvote the problem come here to do their shenanigans and upvote the clever answers and call them a best practice. Bunch of 12 year olds.
This comment is hidden because it contains spoiler information about the solution
I agree. it's not best practise, but it is clever :)
Submitted this same solution and it didn't work.
I don't think it's the best practice. It's less code, however, it's much more resource consuming than a simple condition.
Hi muges,
Sorry, missed you reply.
I've found an issue, I've forgotten to clone the tested array for actual and expected methods.
It's not needed for other languages because expected method is executed first.
But for JS it differs. Assert.equals(actual, expected) - actual ans expected are swapped.
Unfortunately I can't change my tests as it's blocked by the site once more then 1000 users pass it.
But you can change your solution by adding
a = a.slice(0)
to the first line of your method.Thanks for spotting it.
~Cheers
This comment is hidden because it contains spoiler information about the solution
Hi muges,
I aggree that all provided by you array should return 1, 2, 2 accordingly,
But I've double cheked the code and didn't find any issues.
js tests show results in the next format: Expected: 7, instead got: 1 and you can't actually see the tested array of input/random data.
If you want you can provide me your solution (marked spoiler) and I can check it too.
I like this kata. But I think there is a problem with the random javascript test cases:
[ -2, 6, 0, 0, -4, 7, -3 ]
Expected: -1, instead got: 1
[ 8, 7, 2, 0, 6, -4, 7, 0, 6, 2, -2, 8 ]
Expected: -1, instead got: 2
[ 2, -3, -3, 0, 0, 4, 2, 8, 3, 7, -4, 9, 2, 6, 2 ]
Expected: -1, instead got: 2
None of them should result in -1. If I copy this test cases to my working Java solution, all of this tests pass as I would expect and not with -1.
Great, thanks!
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
But this would not work with
null
values as suggested in the instructions, would it?