Count pairs of coordinates connected by a line with slope in the range [ | Function to find the number of pairs of points such that the line passing through them has a slope in the range [ - k , k ] ; Store the result ; Traverse through all the combination of points ; If pair satisfies the given condition ; Increment ans by 1 ; Print the result ; Driver code ; Function Call
function findPairs ( x , y , K ) { let n = x . length ; let ans = 0 ; for ( let i = 0 ; i < n ; ++ i ) { for ( let j = i + 1 ; j < n ; ++ j ) { if ( K * Math . abs ( x [ i ] - x [ j ] ) >= Math . abs ( y [ i ] - y [ j ] ) ) { ++ ans ; } } } document . write ( ans ) ; } let X = [ 2 , 1 , 0 ] , Y = [ 1 , 2 , 0 ] ; let K = 1 ; findPairs ( X , Y , K ) ;