Ad
  • Default User Avatar
  • Custom User Avatar

    if (n >= 1 || typeof n === 'int'){:
    Do you really want or (||)? Also, there is no int type in JavaScript.

  • Custom User Avatar

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

  • Custom User Avatar

    First, if you put ```javascript before and ``` behind your code, it will be formatted like javascript code!

    console.log("You see?")
    

    This help analysing what you have coded.


    Concerning your problem:

    This is said in the kata's description:

    A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.

    So besides the fact that you use Math.abs() I see no problem in your function isPrime(). Just remove this line of code:

    num = Math.abs(num);
    

    To avoid implementing the same piece of code multiple times, I checked wether start is smaller than end and therefore I declared two more variables. Now you can apply these to your loop like this:

    var min = Math.min(start, finish);
    var max = Math.max(start, finish);
    for(var i = min; i < max; i++) {
    
    }
    

    At least, I don't quite know why you want to sort your primes. There is no need for this and it's only one more line of code which can cause an error...

  • Custom User Avatar

    Thanks! Glad you enjoyed it

  • Custom User Avatar

    The tests you see are just a small part of the whole thing that you get once you press "submit".

    I edited this kata a bit, try it now :)

  • Custom User Avatar

    You should always add the error message if possible. That way, one can tell you whether it's a Codewars error or an error with your solution.

  • Custom User Avatar

    You're returning 'arr' inside the for block. You would have to put the return after the for block to make this work.

  • Default User Avatar

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

  • Custom User Avatar

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

  • Custom User Avatar

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