@@ -10,7 +10,7 @@ function AStar(s, e, row, col, inputGrid) {
1010 const start = s ;
1111 const end = e ;
1212
13- function cell ( ) {
13+ function Cell ( ) {
1414 this . cellValue = null ;
1515 this . parent_i = - 1 ;
1616 this . parent_j = - 1 ;
@@ -19,7 +19,7 @@ function AStar(s, e, row, col, inputGrid) {
1919 this . f = Number . MAX_SAFE_INTEGER ;
2020 }
2121
22- function pair ( i , j , f ) {
22+ function Pair ( i , j , f ) {
2323 this . i = i ;
2424 this . j = j ;
2525 this . f = f ;
@@ -30,15 +30,13 @@ function AStar(s, e, row, col, inputGrid) {
3030 for ( let i = 0 ; i < Row ; i += 1 ) {
3131 grid [ i ] = [ ] ;
3232 for ( let j = 0 ; j < Col ; j += 1 ) {
33- grid [ i ] [ j ] = new cell ( ) ;
33+ grid [ i ] [ j ] = new Cell ( ) ;
3434 grid [ i ] [ j ] . cellValue = inputGrid [ i ] [ j ] ;
3535 }
3636 }
3737
3838 const isValid = ( i , j ) => i >= 0 && j >= 0 && i < Row && j < Col ;
39-
4039 const isDestination = ( i , j ) => end . i === i && end . j === j ;
41-
4240 const isBlocked = ( i , j ) => grid [ i ] [ j ] . cellValue === 0 ;
4341
4442 const euclideanDistance = ( i , j ) =>
@@ -64,7 +62,7 @@ function AStar(s, e, row, col, inputGrid) {
6462 }
6563 path . push ( [ i , j ] ) ;
6664
67- for ( let i = 0 ; i < path . length ; i += 1 ) {
65+ for ( let z = 0 ; z < path . length ; z += 1 ) {
6866 console . log ( path [ i ] ) ;
6967 }
7068 } ;
@@ -101,7 +99,7 @@ function AStar(s, e, row, col, inputGrid) {
10199 grid [ i ] [ j ] . h = h ;
102100 grid [ i ] [ j ] . f = g + h ;
103101
104- const item = new pair ( i , j , f ) ;
102+ const item = new Pair ( i , j , f ) ;
105103 // can be improved by using Min-Heap DataStructure
106104 if ( ! openList . length ) {
107105 openList . push ( item ) ;
@@ -123,8 +121,8 @@ function AStar(s, e, row, col, inputGrid) {
123121 return false ;
124122 }
125123
126- let i = start . i ;
127- let j = start . j ;
124+ let { i } = start ;
125+ let { j } = start ;
128126 const openList = [ ] ;
129127 const openListMap = new Map ( ) ;
130128 const closedListMap = new Map ( ) ;
@@ -135,7 +133,7 @@ function AStar(s, e, row, col, inputGrid) {
135133 grid [ i ] [ j ] . g = 0 ;
136134 grid [ i ] [ j ] . f = 0 ;
137135
138- openList . push ( new pair ( i , j , 0.0 ) ) ;
136+ openList . push ( new Pair ( i , j , 0.0 ) ) ;
139137
140138 openListMap [ [ i , j ] ] = 0 ;
141139
0 commit comments