Convert a sentence into its equivalent mobile numeric keypad sequence | Function which computes the sequence ; length of input string ; Checking for space ; Calculating index for each character ; Output sequence ; storing the sequence in array
function printSequence ( arr , input ) { let output = " " ; let n = input . length ; for ( let i = 0 ; i < n ; i ++ ) { if ( input [ i ] == ' ' ) output = output + " " . charCodeAt ( 0 ) ; else { let position = input [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; output = output + arr [ position ] ; } } return output ; } let str = [ " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " ] let input = " " ; document . write ( printSequence ( str , input ) ) ;