66 */
77function convexHull ( points ) {
88 function orientation ( p , q , r ) {
9- const val = ( q . y - p . y ) * ( r . x - q . x ) - ( q . x - p . x ) * ( r . y - q . y )
10- if ( val === 0 ) return 0
11- return val > 0 ? 1 : - 1
9+ const val = ( q . y - p . y ) * ( r . x - q . x ) - ( q . x - p . x ) * ( r . y - q . y ) ;
10+ if ( val === 0 ) return 0 ;
11+ return val > 0 ? 1 : - 1 ;
1212 }
1313
1414 const n = points . length
15- if ( n < 3 ) return points
15+ if ( n < 3 ) return points ;
1616
17- let minPointIndex = 0
17+ let minPointIndex = 0 ;
1818 for ( let i = 0 ; i < n ; i ++ ) {
1919 if (
2020 ( points [ i ] . y < points [ minPointIndex ] . y ) ||
2121 ( points [ i ] . y == points [ minPointIndex ] . y && points [ i ] . x < points [ minPointIndex ] . x )
2222 ) {
23- minPointIndex = i
23+ minPointIndex = i ;
2424 }
2525 }
2626 const sortedPoints = [ ...points ] . sort ( ( a , b ) => {
27- const angleA = Math . atan2 ( a . y - points [ minPointIndex ] . y , a . x - points [ minPointIndex ] . x )
28- const angleB = Math . atan2 ( b . y - points [ minPointIndex ] . y , b . x - points [ minPointIndex ] . x )
29- return angleA - angleB
27+ const angleA = Math . atan2 ( a . y - points [ minPointIndex ] . y , a . x - points [ minPointIndex ] . x ) ;
28+ const angleB = Math . atan2 ( b . y - points [ minPointIndex ] . y , b . x - points [ minPointIndex ] . x ) ;
29+ return angleA - angleB ;
3030 } )
3131
32- const convexHull = [ sortedPoints [ 0 ] , sortedPoints [ 1 ] ]
32+ const convexHull = [ sortedPoints [ 0 ] , sortedPoints [ 1 ] ] ;
3333
3434 for ( let i = 2 ; i < n ; i ++ ) {
3535 while (
@@ -40,12 +40,12 @@ function convexHull(points) {
4040 sortedPoints [ i ]
4141 ) !== - 1
4242 ) {
43- convexHull . pop ( )
43+ convexHull . pop ( ) ;
4444 }
45- convexHull . push ( sortedPoints [ i ] )
45+ convexHull . push ( sortedPoints [ i ] ) ;
4646 }
4747
48- return convexHull
48+ return convexHull ;
4949}
5050
5151/**
@@ -56,11 +56,11 @@ function convexHull(points) {
5656 */
5757function main ( inputX , inputY ) {
5858 if ( inputX == undefined || inputY == undefined ) {
59- inputX = " "
60- inputY = " "
59+ inputX = " " ;
60+ inputY = " " ;
6161 }
62- const xArray = inputX . split ( "," ) . map ( Number )
63- const yArray = inputY . split ( "," ) . map ( Number )
62+ const xArray = inputX . split ( "," ) . map ( Number ) ;
63+ const yArray = inputY . split ( "," ) . map ( Number ) ;
6464
6565 if (
6666 xArray . length < 3 ||
@@ -70,17 +70,17 @@ function main(inputX, inputY) {
7070 ) {
7171 console . log (
7272 'Usage: please provide at least 3 x and y coordinates as separate lists (e.g. "100, 440, 210")'
73- )
74- return
73+ ) ;
74+ return ;
7575 }
7676
77- const points = xArray . map ( ( x , i ) => ( { x, y : yArray [ i ] } ) )
77+ const points = xArray . map ( ( x , i ) => ( { x, y : yArray [ i ] } ) ) ;
7878
79- const convexHullResult = convexHull ( points )
80- convexHullResult . forEach ( ( point ) => console . log ( `(${ point . x } , ${ point . y } )` ) )
79+ const convexHullResult = convexHull ( points ) ;
80+ convexHullResult . forEach ( ( point ) => console . log ( `(${ point . x } , ${ point . y } )` ) ) ;
8181}
8282
8383// Run the executable function with command-line arguments
84- const inputX = process . argv [ 2 ]
85- const inputY = process . argv [ 3 ]
86- main ( inputX , inputY )
84+ const inputX = process . argv [ 2 ] ;
85+ const inputY = process . argv [ 3 ] ;
86+ main ( inputX , inputY ) ;
0 commit comments