How to check if a number is a repdigit number (a natural number composed of repeated digits) in JavaScript

1 Answer

0 votes
function isRepdigitNumber(num) {
    let str = num.toString();
    
    const arr = [...str];
 
    const st = new Set(arr);
    
    return st.size == 1;
}

const num = 8888888;
    
if (isRepdigitNumber(num)) {
    console.log("yes");
} else {
    console.log("no");
}


 
 
/*
run:
 
yes
 
*/

 



answered Feb 8, 2024 by avibootz
edited Feb 8, 2024 by avibootz
...