Queries for counts of array elements with values in given range | function to count elements within given range ; initialize result ; check if element is in range ; driver function ; Answer queries
function countInRange ( arr , n , x , y ) { let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] >= x && arr [ i ] <= y ) count ++ ; } return count ; } let arr = [ 1 , 3 , 4 , 9 , 10 , 3 ] ; let n = arr . length ; let i = 1 , j = 4 ; document . write ( countInRange ( arr , n , i , j ) + " " ) ; i = 9 ; j = 12 ; document . write ( countInRange ( arr , n , i , j ) ) ;