Find whether only two parallel lines contain all coordinates points or not | Find if slope is good with only two intercept ; if set of lines have only two distinct intercept ; Function to check if required solution exist ; check the result by processing the slope by starting three points ; Driver code
function isSlopeGood ( slope , arr , n ) { var setOfLines = new Set ( ) ; for ( var i = 0 ; i < n ; i ++ ) setOfLines . add ( arr [ i ] - slope * ( i ) ) ; return setOfLines . size == 2 ; } function checkForParallel ( arr , n ) { var slope1 = isSlopeGood ( arr [ 1 ] - arr [ 0 ] , arr , n ) ; var slope2 = isSlopeGood ( arr [ 2 ] - arr [ 1 ] , arr , n ) ; var slope3 = isSlopeGood ( parseInt ( ( arr [ 2 ] - arr [ 0 ] ) / 2 ) , arr , n ) ; if ( slope1 slope2 slope3 ) { return 1 ; } return 0 ; } var arr = [ 1 , 6 , 3 , 8 , 5 ] ; var n = arr . length ; document . write ( checkForParallel ( arr , n ) ) ;