I had tried this piece of code in java which is working properly fine but while switching in javascript it is not working properly.
function checkNumberIfContainsKey(number, key){
while(number > 0){
if(number%10 == key){
return true;
}
number /= 10;
}
return false;
}
console.log(checkNumberIfContainsKey(19, 9));
console.log(checkNumberIfContainsKey(191, 9));
console.log(checkNumberIfContainsKey(912, 9));
console.log(checkNumberIfContainsKey(854, 9));
this function should return true if it contains key at any position. example: checkNumberIfContainsKey(19, 9) output: true
my expected output:
checkNumberIfContainsKey(19, 9) //true
checkNumberIfContainsKey(191, 9) //true
checkNumberIfContainsKey(912, 9) //true
checkNumberIfContainsKey(185, 9) //false
my output:
checkNumberIfContainsKey(19, 9) //true
checkNumberIfContainsKey(191, 9) //false
checkNumberIfContainsKey(912, 9) //false
checkNumberIfContainsKey(185, 9) //false