Ad
  • Custom User Avatar

    it works 100%

    my code fails

    Pick one :/

  • Custom User Avatar

    reviewd my code and tested it on all combination - it works 100%. I have an internal error
    and it makes sense -> my code fails always on the 15 test - the test are random and I found it fails
    on tests which I allready succeeded in previuos attempts. ):

  • Custom User Avatar

    I just solved it myself and it's working fine, except that assertion messages are horrible. Not working code != kata issue.

    Please refer to https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution for some tips.

  • Custom User Avatar

    The error is coming from your code, not the tests... And if not, you'll have to prove it.

  • Custom User Avatar

    The error is:
    TypeError: Cannot read property '0' of undefined
    at addPositions
    at turg
    at /home/codewarrior/index.js:315:29
    at /home/codewarrior/index.js:513:5
    at Object.handleError

    thrown after solving all the tests - the reason I'm not specific is that if I include my code than the message is hidden and I can't see it since it does not let me solve it.

  • Custom User Avatar

    What's the error??? And why is that a kata issue? (I haven't solved it, so I can't see your fiddle)

    If you're gonna raise an issue, please BE SPECIFIC.

  • Custom User Avatar

    My solution works for any givven position of the K tested on the site and in jsffidle.
    When I submit it throws a js error after passing all the tests -> check the hidden comment with the link to the fiddle
    test that iterate all possible cases...

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    No, your solution isn't "much more efficient". Only one iteration is needed. You still iterate two or three times.

  • Default User Avatar

    You don't even need to filter the whole array, just the first 3 numbers.

  • Custom User Avatar

    your solution must be top one

  • Default User Avatar

    It actually takes 3N iterations. The result can be found by the third number, so no real need to loop further.

    Sometimes I feel we FE devs get so caught up in functional programming we forget about efficiency of implementation.

  • Default User Avatar

    Thank you.

    The second condition covers n = 0 as 0 % 2 === 0 resolves to true, so n < 0 is OK. It could be n < 1 if you want to make your code a bit "faster".

  • Custom User Avatar

    Should be n < 1 :)

    Zero is not a diamont 1 is the smallest.

    Great Solution!!!

  • Custom User Avatar

    You don't need to filter both every time - Just filter evens and if evens length is greater than 1
    then you can filter the odds inside the terinary condition.
    Also no need to parse int JS will assume its numbers by it self.... :)

    Take a look at my answer its much more efficient