Print all strings from given array that can be typed using keys from a single row of a QWERTY keyboard | Function to print all strings that can be typed using keys of a single row in a QWERTY Keyboard ; Stores row number of all possible character of the strings ; Traverse the array ; If current string is not an empty string ; Sets true / false if a string can be typed using keys of a single row or not ; Stores row number of the first character of current string ; Stores length of word ; Traverse current string ; If current character can 't be  typed using keys of rowNum only ; Update flag ; If current string can be typed using keys from rowNum only ; Print the string ; Driver Code
function findWordsSameRow ( arr ) { var mp = { } ; mp [ " " ] = 1 ; mp [ " " ] = 1 ; mp [ " " ] = 1 ; mp [ " " ] = 1 ; mp [ " " ] = 1 ; mp [ " " ] = 1 ; mp [ " " ] = 1 ; mp [ " " ] = 1 ; mp [ " " ] = 1 ; mp [ " " ] = 1 ; mp [ " " ] = 2 ; mp [ " " ] = 2 ; mp [ " " ] = 2 ; mp [ " " ] = 2 ; mp [ " " ] = 2 ; mp [ " " ] = 2 ; mp [ " " ] = 2 ; mp [ " " ] = 2 ; mp [ " " ] = 2 ; mp [ " " ] = 3 ; mp [ " " ] = 3 ; mp [ " " ] = 3 ; mp [ " " ] = 3 ; mp [ " " ] = 3 ; mp [ " " ] = 3 ; mp [ " " ] = 3 ; for ( const word of arr ) { if ( word . length !== 0 ) { var flag = true ; var rowNum = mp [ word [ 0 ] . toLowerCase ( ) ] ; var M = word . length ; for ( var i = 1 ; i < M ; i ++ ) { if ( mp [ word [ i ] . toLowerCase ( ) ] !== rowNum ) { flag = false ; break ; } } if ( flag ) { document . write ( word + " " ) ; } } } } var words = [ " " , " " , " " , " " ] ; findWordsSameRow ( words ) ;