Quick way to check if all the characters of a string are same | Function to check is all the characters in string are or not ; Insert characters in the set ; If all characters are same Size of set will always be 1 ; Driver Code
function allCharactersSame ( s ) { let s1 = new Set ( ) ; for ( let i = 0 ; i < s . length ; i ++ ) { s1 . add ( s [ i ] ) ; } if ( s1 . size == 1 ) document . write ( " " ) ; else document . write ( " " ) ; } let str = " " ; allCharactersSame ( str ) ;