Cost to make a string Panagram | Function to return the total cost required to make the string Pangram ; Mark all the alphabets that occurred in the string ; Calculate the total cost for the missing alphabets ; Driver Code
function pangramCost ( arr , str ) { var cost = 0 ; var occurred = new Array ( 26 ) ; for ( let i = 0 ; i < 26 ; i ++ ) occurred [ i ] = false ; for ( let i = 0 ; i < str . length ; i ++ ) occurred [ str [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] = true ; for ( let i = 0 ; i < 26 ; i ++ ) { if ( occurred [ i ] == false ) cost += arr [ i ] ; } return cost ; } var arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 , 25 , 26 ] ; var str = " " ; document . write ( pangramCost ( arr , str ) ) ;