Ad
  • Custom User Avatar

    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

  • Custom User Avatar

    Hey rekbil,

    Your algorithm doesn't take into account the following condition (marked in bold):

    "Same" means, here, that the elements in b are the elements in a squared, regardless of the order.

    Read carefully the description once again and try to figure out how to change your algorithm to satisfy all conditions.

  • Custom User Avatar

    Now I understand.

  • Custom User Avatar

    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 B

    OR

    (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 B

    In 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. %)

  • Custom User Avatar

    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?

  • Custom User Avatar

    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.

  • Custom User Avatar
  • Custom User Avatar

    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.

  • Custom User Avatar

    for (let i = 0; i <= input.length; i++)

  • Custom User Avatar

    Hi BobAllan123,

    which language do you use?

    Please post your complete solution and an error message.

  • Custom User Avatar

    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.

  • Custom User Avatar

    Hi Hisham.Taha,

    the error message says all you need: Cannot read property 'map' of null. It can happen, if the input value a is null, right? So, you need to check the input value for null. (carefully read the description once again)

  • Custom User Avatar

    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.

  • Custom User Avatar

    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.

  • Custom User Avatar

    Hi Unnamed,

    yes, you are right, with array instead of map it would be definitely faster. Thank you for clarifying that point.

  • Loading more items...