Check if all characters of a string can be made equal by increments or decrements | Function to check if it is possible to make all characters of string S same or not ; Length of string ; Stores the sum of ASCII value ; Traverse the string S ; Update the weightOfString ; If the sum is divisible by N then print " Yes " ; Otherwise print " No " ; Driver Code
function canMakeEqual ( S ) { var N = S . length ; var weightOfString = 0 ; for ( var i = 0 ; i < N ; i ++ ) { weightOfString += S . charAt ( i ) . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) + 1 ; } if ( weightOfString % N == 0 ) document . write ( " " ) ; else document . write ( " " ) ; } var S = " " ; canMakeEqual ( S ) ;