728x90
function findRange(num) {
const numStr = num.toString();
let min = 0;
let max = 0;
let changeIndex = 0;
if(numStr[changeIndex] === '1') {
changeIndex++;
while(changeIndex < numStr.length && (numStr[changeIndex] === '0' || numStr[changeIndex] === '1' )) {
changeIndex++;
}
min = numStr.replaceAll(numStr[changeIndex],'0');
} else {
min = numStr.replaceAll(numStr[changeIndex],'1');
}
changeIndex = 0;
if (numStr[changeIndex] === '9') {
changeIndex++;
while(changeIndex < numStr.length && numStr[changeIndex] === '9') {
changeIndex++;
}
}
max = numStr.replaceAll(numStr[changeIndex],'9');
const result = Number(max) - Number(min);
return result;
}
728x90