The goal is to determine if a number is Hamming number?! As we know Hamming number is a number that contains only 2, 3 and 5 as factors. That means that a number must not contain any prime number greater than 5! So I created a function isPrimeNumber that determines if a number is prime, and thereafter I created function that determines if a number contains factors 2, 3 and 5?!
function isPrimeNumber(n){
if(n===1){
return true;
}else if((n%1!==0)||(n<=0)){
return false;
}else{
for (var i=2; i<n; i++){
if (n%i===0)
return false;
}
return true;
}
}
function isHamming(n){
if(((n%2===0)||(n%3===0)||(n%5===0))){
return true;
}else if((isPrimeNumber(n)===true)&&(n>=7)){
return false;
}else{
return false;
}
}
Would like to combine those two functions to determine if a number entered is Hamming number or not?!