Probability of a key K present in array | Function to find the probability ; find probability ; Driver Code
function kPresentProbability ( a , n , k ) { let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) if ( a [ i ] == k ) count += 1 ; return count / n ; } let A = [ 4 , 7 , 2 , 0 , 8 , 7 , 5 ] ; let K = 3 ; let N = A . length ; document . write ( kPresentProbability ( A , N , K ) ) ;