Check if the string contains consecutive letters and each letter occurs exactly once | Function to check if the condition holds ; Get the length of the string ; sort the given string ; Iterate for every index and check for the condition ; If are not consecutive ; 1 st example ; 2 nd example
function check ( s ) { let l = s . length ; s . sort ( ) ; for ( let i = 1 ; i < l ; i ++ ) { if ( ( s [ i ] . charCodeAt ( ) - s [ i - 1 ] . charCodeAt ( ) ) != 1 ) return false ; } return true ; } let str = " " ; if ( check ( str . split ( ' ' ) ) == true ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ; let str1 = " " ; if ( check ( str1 . split ( ' ' ) ) == true ) document . write ( " " ) ; else document . write ( " " ) ;