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 122 views
1 answer 112 views
1 answer 126 views
1 answer 144 views
1 answer 125 views
1 answer 118 views
1 answer 130 views
...