To store the number of points has same x or y coordinates
var xpoints = { } ; var ypoints = { } ; for ( var i = 0 ; i < n ; i ++ ) { if ( xpoints . hasOwnProperty ( a [ i ] [ 0 ] ) ) { xpoints [ a [ i ] [ 0 ] ] = xpoints [ a [ i ] [ 0 ] ] + 1 ; } else { xpoints [ a [ i ] [ 0 ] ] = 1 ; } if ( ypoints . hasOwnProperty ( a [ i ] [ 1 ] ) ) { ypoints [ a [ i ] [ 1 ] ] = ypoints [ a [ i ] [ 1 ] ] + 1 ; } else { ypoints [ a [ i ] [ 1 ] ] = 1 ; } }