I got problems when doing "Steps in Primes" of Codewars.
Make function step(g,m,n) which g=step >= 2 , m=begin number >=2, n=last number>= n. Step(g,m,n) will return the first match [a,b] which m < a,b is prime < n and a+g=b.
I did right in basic test cases but when i submit , i got infinity loop somewhere. Can anyone give me suggestion?
function isInt(n) {
    if(typeof n==='number' && (n%1)===0) {
        return true;
    }
    else return false;
}
function step(g, m, n) {
    if(isInt(g) && isInt(m) && isInt(n) &&g >= 2 && m >= 2 && n>=m) {      
        var p=[];
        var ans=[];
        for (var temp=m; temp<=n;temp++)
        {
            var a=0;
            for (var chk=2; chk<temp-1;chk++)
                if (temp%chk===0) a++;
            if (a===0) p.push(temp);
        }    
        for (var a=0;a<p.length-1;a++)
        {
            for (var b=a+1;b<p.length;b++)
                if (p[b]===(p[a]+g)) return [p[a],p[b]];
        }
    }
    return "nil";
}
 
     
    