# Javascript Code Optimization

I am trying to complete this codewars challenge called “Gap in Primes”. The instructions are to find two prime numbers within a certain range with a certain gap between them. I should return the first two prime numbers within the range specified with the gap selected.

I’ve written a bit of code that works but its too inefficient for me to pass the challenge. Could someone help me clean up my code. Please don’t just tell me the answer, if possible could you please point me in the right direction. That would be greatly appreciated!

``````function gap(g, m, n) {

var stopNumber;
var checkIfInteger;
var arrayIndex = 0;
var gap;

//iterate through all of the numbers in the range and find if they're prime
for( var numberToCheck  = m; numberToCheck <= n; numberToCheck++){

var checkedTwoAndThreePass = true;

checkIfInteger = numberToCheck / 2;

if(Number.isInteger(checkIfInteger)){
checkedTwoAndThreePass = false;
}

checkIfInteger = numberToCheck / 3;

if(Number.isInteger(checkIfInteger)){
checkedTwoAndThreePass = false;
}

if(checkedTwoAndThreePass){

var k = 1;

stopNumber = Math.sqrt(numberToCheck);

while( ((6 * k) - 1) <= stopNumber & primeNumberCheck === true ){

checkIfInteger = numberToCheck / ((6 * k) - 1);

if(Number.isInteger(checkIfInteger)){
}
else{

checkIfInteger = numberToCheck / ((6 * k) + 1);

if(Number.isInteger(checkIfInteger)){
}
}
k++;
}

arrayIndex++;
}

}

}

for(var i = 0; i < primeNumbersInRange.length; i++){