Program to print characters present at prime indexes in a given string | Javascript program to print characters at Prime index in a given String ; Corner case ; Check from 2 to n - 1 ; Function to print character at prime index ; Loop to check if index prime or not ; Driver code
function isPrime ( n ) { if ( n <= 1 ) return false ; for ( let i = 2 ; i < n ; i ++ ) if ( n % i == 0 ) return false ; return true ; } function prime_index ( input ) { let n = input . length ; for ( let i = 2 ; i <= n ; i ++ ) if ( isPrime ( i ) ) document . write ( input [ i - 1 ] ) ; } let input = " " ; prime_index ( input ) ;