Check whether the string can be printed using same row of qwerty keypad | Function to find the row of the character in the qwerty keypad ; Sets to include the characters from the same row of the qwerty keypad ; Condition to check the row of the current character of the string ; Function to check the characters are from the same row of the qwerty keypad ; Driver code
function checkQwertyRow ( x ) { var first_row = [ " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , ] ; var second_row = [ " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , ] ; var third_row = [ " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , ] ; var fourth_row = [ " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , ] ; if ( first_row . includes ( x ) ) { return 1 ; } else if ( second_row . includes ( x ) ) { return 2 ; } else if ( third_row . includes ( x ) ) { return 3 ; } else if ( fourth_row . includes ( x ) ) { return 4 ; } return 0 ; } function checkValidity ( str ) { var x = str [ 0 ] ; var row = checkQwertyRow ( x ) ; for ( var i = 0 ; i < str . length ; i ++ ) { x = str [ i ] ; if ( row !== checkQwertyRow ( x ) ) { return false ; } } return true ; } var str = " " ; if ( checkValidity ( str ) ) document . write ( " " ) ; else document . write ( " " ) ;