How to check if a string contains identical digits in Node.js

1 Answer

0 votes
function isStringContainIdenticalDigits(str) {
    const arr = [...str];
    const st = new Set(arr);
 
    return st.size == 1;
}
 
let str = "5555555555";
console.log(isStringContainIdenticalDigits(str) ? "yes" : "no");
 
str = "255555555";
console.log(isStringContainIdenticalDigits(str) ? "yes" : "no");
 
 
 
/*
run:
 
yes
no
 
*/

 



answered Mar 2, 2024 by avibootz

Related questions

2 answers 179 views
1 answer 124 views
1 answer 114 views
1 answer 128 views
1 answer 146 views
1 answer 128 views
1 answer 120 views
...