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.
Hi
Raxxillion
,I understand your frustration and agree with you that having a good set of sample unit tests is always very comfortable and let you concentrate on the actual solving of a problem.
However, I think the lack of many sample unit tests is a good chance to work on a problem following TDD (you can write as many unit tests as you need to check all (edge) cases thoroughly). It's a good practice. In the end, the practice is a main goal here on the codewars.
Kind regards,
Dentzil
Hey
rekbil
,Your algorithm doesn't take into account the following condition (marked in bold):
Read carefully the description once again and try to figure out how to change your algorithm to satisfy all conditions.
Now I understand.
From the description
... A and B friends if each integer from the array divisors is either a divisor of both A and B or neither A nor B
.So, then for divisors array [d1, d2] two numbers A and B are valid friends numbers if
(A % d1 == 0 AND B % d1 == 0) AND (A % d2 == 0 AND B % d2 == 0)
- each integer from the array divisors is a divisor of both A and BOR
(A % d1 != 0 AND B % d1 != 0) AND (A % d2 != 0 AND B % d2 != 0)
- each integer from the array divisors is a divisor of neither A nor BIn other cases the numbers are not valid friends numbers.
Or do I see it wrong?
But this thing with friends numbers is completely unnecessary. Since the kata is not about the friends numbers and for the solution it's not matter if numbers are friends numbers or not. %)
Your comment bellow doesn't answer, why 2 and 4 are friends. They can be in the same clan as you wrote, but they are not friends.
What does the kata ultimately have to do with the
friends numbers
?Hi
myjinxin2015
,in the description you say:
two integers A and B friends if each integer from the array divisors is either a divisor of both A and B or neither A nor B
.For the example
divisors = [2, 3] and k = 6
there are one firends paar 1 and 5, since none of each divisors is divisor of both 1 and 5. It's consistent with the description.But why are 2 and 4 friends? Both, 2 and 4, have only one divisor 2. To be friends they don't satisfy the rule in the description.
https://github.com/nunit/docs/wiki/Assert.AreEqual#comparing-arrays-and-collections
Are you sure that Assert.AreEqual() cannot compare two single-dimensioned arrays of integers?
And how does it currently work in your opinion? Each test should be failed. But they are not.
for (let i = 0; i
<=
input.length; i++)Hi
BobAllan123
,which language do you use?
Please post your complete solution and an error message.
Hi
Hisham.Taha
,what do you mean by
all values tests
?According to your screenshot, your programm doesn't pass the wrong values tests. There are only two tests in this section, namely with the empty input value (
[]
) and with the null input value (null
).You should just improve your programm so, that it can react proper for wrong values inputs. Nothing more.
Hi
Hisham.Taha
,the error message says all you need:
Cannot read property 'map' of null
. It can happen, if the input valuea
isnull
, right? So, you need to check the input value for null. (carefully read the description once again)Hi,
in order to get the Length-property or generally to interact with an object, it needs to be ensured that the object is not null. So, the null check should be evaluated first, before the length check.
Take a look at this msdn article.
Hi,
you wrote
This code works well on my local machine, but it is showing some error here.
.Then compare the code on your local machine with the code you have posted.
Hi
Unnamed
,yes, you are right, with
array
instead ofmap
it would be definitely faster. Thank you for clarifying that point.Loading more items...