Find prime numbers in the first half and second half of an array | Function to check if a number is prime or not ; Function to find whether elements are prime or not ; Traverse in the given range ; Check if a number is prime or not ; Function to print the prime numbers in the first half and second half of an array ; Driver Code ; Function call
function prime ( n ) { for ( let i = 2 ; i * i <= n ; i ++ ) if ( n % i == 0 ) return false ; return true ; } function prime_range ( start , end , a ) { for ( let i = start ; i < end ; i ++ ) { if ( prime ( a [ i ] ) ) document . write ( a [ i ] + " " ) ; } } function Print ( arr , n ) { document . write ( " " ) ; prime_range ( 0 , parseInt ( n / 2 ) , arr ) ; document . write ( " " ) ; document . write ( " " ) ; prime_range ( parseInt ( n / 2 ) , n , arr ) ; document . write ( " " ) ; } let arr = [ 2 , 5 , 10 , 15 , 17 , 21 , 23 ] ; let n = arr . length ; Print ( arr , n ) ;