How to check if a string contains identical digits in JavaScript

1 Answer

0 votes
function isStringContainIdenticalDigits(str) {
    const arr = [...str];
    const st = new Set(arr);

    return st.size == 1;
}

let str = "8888888";
console.log(isStringContainIdenticalDigits(str) ? "yes" : "no");

str = "18888888";
console.log(isStringContainIdenticalDigits(str) ? "yes" : "no");



/*
run:

yes
no

*/

 



answered Mar 2, 2024 by avibootz

Related questions

1 answer 195 views
1 answer 200 views
1 answer 193 views
1 answer 216 views
1 answer 205 views
1 answer 189 views
1 answer 246 views
...