Check if number can be made prime by deleting a single digit | Function to check if N is prime ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; Function to delete character at index i from given String str ; Deletes character at position 4 ; Function to check if a number becomes prime by deleting any digit ; Converting the number to String ; length of String ; number should not be of single digit ; Loop to find all numbers after deleting a single digit ; Deleting ith character from the String ; converting String to let ; Driver Code
function isPrime ( n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( let i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } function deleteIth ( str , i ) { str = str . substr ( 0 , i ) + str . substr ( i + 1 ) ; return str ; } function isPrimePossible ( N ) { let s = N . toString ( ) ; let l = s . length ; if ( l < 2 ) return false ; for ( let i = 0 ; i < l ; i ++ ) { let str = deleteIth ( s , i ) ; let num = parseInt ( str ) ; if ( isPrime ( num ) ) return true ; } return false ; } let N = 610 ; if ( isPrimePossible ( N ) ) document . write ( " " ) ; else document . write ( " " ) ;