Find if an array contains a string with one mismatch | Javascript program to find if given string is present with one mismatch . ; If the array is empty ; If sizes are same ; If first mismatch ; Second mismatch ; Driver code
function check ( list , s ) { let n = list . length ; if ( n == 0 ) { return false ; } for ( let i = 0 ; i < n ; i ++ ) { if ( list [ i ] . length != s . length ) { continue ; } let diff = false ; for ( let j = 0 ; j < list [ i ] . length ; j ++ ) { if ( list [ i ] [ j ] != s [ j ] ) { if ( ! diff ) { diff = true ; } else { diff = false ; break ; } } } if ( diff ) { return true ; } } return false ; } let s = [ ] ; s . push ( " " ) ; s . push ( " " ) ; s . push ( " " ) ; s . push ( " " ) ; s . push ( " " ) ; document . write ( check ( s , " " ) == true ? 1 : 0 ) ;