Earn extra honor and gain new allies!
Honor is earned for each new codewarrior who joins.
Learn more
  • This comment is hidden because it contains spoiler information about the solution

  • I really enjoyed doing this kata!
    Pair programmed on this kata with a friend, leading us to find and understand the most optimized logic that I have ever come across.
    Infact, I will be using this logic for the rest of my life! (i.e... I ever need to :P)

    Thanks for this kata though. Simple and straightforward :)

  • Objective-C Translation Kumited - please accept :D

  • It should be definetely rated as 6 or 7.

  • It is because the mistake doesnt refer to the test input 43 but to the test above....-1.

  • I am getting this result for 43 from the isPrime function: Expected: false, instead got: true
    I returned true because 43 is a prime number. What am I missing?

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

  • 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...

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

  • tests run succsessful but when i submit i get RangeError: Invalid array length
    at isPrime
    what case i dont test?

  • There seems to be an additional test that gets run on submit that doesn't exist in the test cases. It fails: "Expected: false, instead got: true" and I have no idea why.

  • Here also, putting a range in as you did, 3070, 1530, runs my tests correctly (on my own node server), but here the expected results begin with a value lower than my starting value.

  • Your tests, seem to be a bit awry for larger numbers, I can get a full pass up to 10,000 from 0 all primes, however, submitting, throws some lengthy expectations, for which I have no idea which ranges you were testing. since my 0,10000 was well within the range, which passed, can you revaluate your tests, since there are many issues shown here in the comments too. In fact on your expected values there are numbers which are not primes. Testting seems to be an issue on the lower kyus, the kata are fun, but when a submission test case passes a large number of tests apart from one, its often frustrating as there is no way to see where the test failed. For example, the array is so long that its even complex to compare expected and actual, and even then, we have no idea what range failed.

    As I mentioned, i can pass with no issue all primes from 0,10000 yet on submision I get some bizzare and lengthy fail for a range well below that, since this cant pass, we cant progress or fix it on this task- I would suggest a better approach to writing the submission tests, how they fail when the basic tests pass is a mystery. Even more a mystery, I am getting a different expected on each new submission?

    This is the third 5kyu kata where local tests pass but vague tests fail on submission. To date, two of those Kata the author found errors in the tests he wrote.

  • don't like this... My Test shows me the array from 0 to 3000 and no problems with timeout... How far do I need to be able to go here?

    This returns an empty array []. If I reduce the range from (700,1000) to (700,999) I get all prime numbers... So when I try to submit, I pass many tests but at some point there comes a range that my algorithm doesn't solve... why's that? Please try not to spoil too much in the answers. I want to be able to see them. Btw: How can I indent my code?

    function isPrime(number) {

    if (number < 2) return false;

    if (number == 2 || number == 3 ) return true;

    for (var i=2; i<Math.ceil(Math.sqrt(number))+1; i++) {

    if (number%i==0) return false;


    return true;


    function getPrimes(start, finish) {

    var a = [start, finish];

    a = a.sort();

    for (var i=a[0],res=[]; i<a[1]+1; i++) {

    if (isPrime(i)) {




    return res;



  • Loading more items...