@@ -54,20 +54,21 @@ const processMap = (map, pointer_map, order_list, max_key) => {
54
54
55
55
let curr_list = [ ] ;
56
56
57
- console . log ( "~> top" )
58
- top = findNeighbours ( first , { ...map , ...pointer_map } , 'y' , 0 , - 1 , [ ] )
59
- // right = x + 1
60
- console . log ( "~> right" )
61
- // console.log(top)
62
- right = findNeighbours ( first , { ...map , ...pointer_map } , 'x' , 1 , 0 , [ ] )
63
- // bottom = y + 1
64
- console . log ( "~> bottom" )
65
- // console.log([...top, ...right])
66
- bottom = findNeighbours ( first , { ...map , ...pointer_map } , 'y' , 0 , 1 , [ ] )
67
- // left = x - 1
68
- console . log ( "~> left" )
69
- // console.log([...top, ...right, ...bottom])
70
- left = findNeighbours ( first , { ...map , ...pointer_map } , 'x' , - 1 , 0 , [ ] )
57
+ let expanded_list = expandFromNode ( map , pointer_map ) ;
58
+ // console.log("~> top")
59
+ // top = findNeighbours(first, { ...map, ...pointer_map }, 'y', 0, -1, [])
60
+ // // right = x + 1
61
+ // console.log("~> right")
62
+ // // console.log(top)
63
+ // right = findNeighbours(first, { ...map, ...pointer_map }, 'x', 1, 0, [])
64
+ // // bottom = y + 1
65
+ // console.log("~> bottom")
66
+ // // console.log([...top, ...right])
67
+ // bottom = findNeighbours(first, { ...map, ...pointer_map }, 'y', 0, 1, [])
68
+ // // left = x - 1
69
+ // console.log("~> left")
70
+ // // console.log([...top, ...right, ...bottom])
71
+ // left = findNeighbours(first, { ...map, ...pointer_map }, 'x', -1, 0, [])
71
72
72
73
console . log ( "pointer_map" )
73
74
console . log ( pointer_map )
@@ -81,7 +82,7 @@ const processMap = (map, pointer_map, order_list, max_key) => {
81
82
let new_max_key = max_key + 1 ;
82
83
83
84
console . log ( `~> new_max_key: ${ new_max_key } ` )
84
- let expanded_list = [ ...top , ...right , ...bottom , ...left ] ;
85
+ // let expanded_list = [...top, ...right, ...bottom, ...left];
85
86
// let next_first = map[expanded_list.sort()[0]] || map[Object.keys(map)[0]];
86
87
// let next_first = map[Object.keys(map)[0]];
87
88
// let next_first = map[expanded_list.sort((a, b) => a - b)[0]] || map[Object.keys(map)[0]];
@@ -175,6 +176,26 @@ const processMap = (map, pointer_map, order_list, max_key) => {
175
176
return processMap ( map , pointer_map , order_list , max_key ) ;
176
177
}
177
178
179
+ const expandFromNode = ( map , pointer_map ) => {
180
+ let node = map [ Object . keys ( map ) [ 0 ] ] ;
181
+
182
+ console . log ( "~> top" )
183
+ top = findNeighbours ( node , { ...map , ...pointer_map } , 'y' , 0 , - 1 , [ ] )
184
+ // right = x + 1
185
+ console . log ( "~> right" )
186
+ // console.log(top)
187
+ right = findNeighbours ( node , { ...map , ...pointer_map } , 'x' , 1 , 0 , [ ] )
188
+ // bottom = y + 1
189
+ console . log ( "~> bottom" )
190
+ // console.log([...top, ...right])
191
+ bottom = findNeighbours ( node , { ...map , ...pointer_map } , 'y' , 0 , 1 , [ ] )
192
+ // left = x - 1
193
+ console . log ( "~> left" )
194
+ // console.log([...top, ...right, ...bottom])
195
+ left = findNeighbours ( node , { ...map , ...pointer_map } , 'x' , - 1 , 0 , [ ] )
196
+
197
+ return [ ...top , ...right , ...bottom , ...left ] ;
198
+ }
178
199
// Find neighbours going outwards like a +, neighbours will include the current node
179
200
const findNeighbours = ( current_node , map , attr , x_operator , y_operator , neighbours ) => {
180
201
// console.log("findNeighbours -> map")
@@ -211,12 +232,12 @@ const findNeighbours = (current_node, map, attr, x_operator, y_operator, neighbo
211
232
return findNeighbours ( current_node , map , attr , x_operator , y_operator , neighbours ) ;
212
233
}
213
234
214
- // numIslands([
215
- // ["1", "1", "0", "0", "0"],
216
- // ["1", "1", "0", "0", "0"],
217
- // ["1", "0", "1", "0", "0"],
218
- // ["1", "0", "0", "1", "1"]
219
- // ]);
235
+ numIslands ( [
236
+ [ "1" , "1" , "0" , "0" , "0" ] ,
237
+ [ "1" , "1" , "0" , "0" , "0" ] ,
238
+ [ "1" , "0" , "1" , "0" , "0" ] ,
239
+ [ "1" , "0" , "0" , "1" , "1" ]
240
+ ] ) ;
220
241
221
242
// numIslands([
222
243
// ["1", "1", "1"],
@@ -260,25 +281,25 @@ const findNeighbours = (current_node, map, attr, x_operator, y_operator, neighbo
260
281
// ["1", "0", "1", "1", "1", "1", "1", "1", "1", "0"]
261
282
// ])
262
283
263
- numIslands ( [
264
- [ "0" , "1" , "0" , "0" , "1" , "1" , "1" , "0" , "0" , "0" , "0" , "0" , "1" , "0" , "0" , "0" , "0" , "1" , "0" , "1" ] ,
265
- [ "1" , "0" , "1" , "0" , "0" , "1" , "1" , "0" , "0" , "1" , "0" , "1" , "0" , "1" , "0" , "1" , "1" , "0" , "0" , "0" ] ,
266
- [ "0" , "1" , "0" , "0" , "0" , "1" , "1" , "1" , "1" , "0" , "0" , "0" , "0" , "0" , "1" , "1" , "1" , "1" , "0" , "1" ] ,
267
- [ "1" , "1" , "0" , "0" , "0" , "1" , "1" , "0" , "0" , "0" , "1" , "1" , "1" , "0" , "0" , "1" , "0" , "1" , "1" , "0" ] ,
268
- [ "0" , "1" , "0" , "1" , "1" , "0" , "1" , "0" , "0" , "0" , "1" , "0" , "0" , "1" , "0" , "0" , "0" , "0" , "0" , "1" ] ,
269
- [ "1" , "0" , "0" , "1" , "0" , "1" , "0" , "0" , "0" , "1" , "1" , "0" , "1" , "0" , "0" , "1" , "0" , "0" , "0" , "0" ] ,
270
- [ "1" , "0" , "0" , "0" , "1" , "1" , "0" , "0" , "0" , "0" , "0" , "1" , "0" , "0" , "1" , "0" , "0" , "0" , "0" , "1" ] ,
271
- [ "1" , "0" , "0" , "0" , "1" , "0" , "1" , "1" , "1" , "0" , "1" , "0" , "1" , "1" , "1" , "1" , "0" , "0" , "0" , "1" ] ,
272
- [ "1" , "0" , "0" , "1" , "0" , "0" , "0" , "1" , "0" , "0" , "0" , "0" , "0" , "0" , "0" , "0" , "0" , "1" , "0" , "1" ] ,
273
- [ "0" , "0" , "0" , "1" , "0" , "1" , "1" , "1" , "1" , "1" , "1" , "1" , "1" , "1" , "0" , "0" , "0" , "0" , "1" , "0" ] ,
274
- [ "1" , "0" , "1" , "0" , "1" , "0" , "0" , "1" , "1" , "1" , "0" , "1" , "1" , "0" , "0" , "1" , "1" , "0" , "0" , "0" ] ,
275
- [ "0" , "1" , "0" , "0" , "1" , "0" , "0" , "0" , "0" , "0" , "0" , "1" , "1" , "1" , "1" , "0" , "0" , "0" , "1" , "0" ] ,
276
- [ "1" , "0" , "0" , "0" , "1" , "1" , "1" , "0" , "1" , "0" , "0" , "0" , "1" , "0" , "1" , "0" , "1" , "0" , "0" , "1" ] ,
277
- [ "0" , "0" , "0" , "0" , "1" , "0" , "1" , "1" , "0" , "1" , "0" , "1" , "0" , "1" , "1" , "1" , "1" , "0" , "0" , "0" ] ,
278
- [ "0" , "1" , "1" , "0" , "0" , "0" , "0" , "1" , "0" , "0" , "1" , "1" , "1" , "0" , "0" , "1" , "1" , "0" , "1" , "0" ] ,
279
- [ "1" , "0" , "1" , "1" , "1" , "1" , "1" , "1" , "0" , "1" , "1" , "0" , "1" , "0" , "0" , "1" , "0" , "0" , "0" , "1" ] ,
280
- [ "1" , "0" , "0" , "0" , "1" , "0" , "1" , "0" , "0" , "1" , "0" , "1" , "0" , "0" , "1" , "0" , "0" , "1" , "1" , "1" ] ,
281
- [ "0" , "0" , "1" , "0" , "0" , "0" , "0" , "1" , "0" , "0" , "1" , "1" , "0" , "1" , "1" , "1" , "0" , "0" , "0" , "0" ] ,
282
- [ "0" , "0" , "1" , "0" , "0" , "0" , "0" , "0" , "0" , "1" , "1" , "0" , "1" , "0" , "1" , "0" , "0" , "0" , "1" , "1" ] ,
283
- [ "1" , "0" , "0" , "0" , "1" , "0" , "1" , "1" , "1" , "0" , "0" , "1" , "0" , "1" , "0" , "1" , "1" , "0" , "0" , "0" ]
284
- ] )
284
+ // numIslands([
285
+ // ["0", "1", "0", "0", "1", "1", "1", "0", "0", "0", "0", "0", "1", "0", "0", "0", "0", "1", "0", "1"],
286
+ // ["1", "0", "1", "0", "0", "1", "1", "0", "0", "1", "0", "1", "0", "1", "0", "1", "1", "0", "0", "0"],
287
+ // ["0", "1", "0", "0", "0", "1", "1", "1", "1", "0", "0", "0", "0", "0", "1", "1", "1", "1", "0", "1"],
288
+ // ["1", "1", "0", "0", "0", "1", "1", "0", "0", "0", "1", "1", "1", "0", "0", "1", "0", "1", "1", "0"],
289
+ // ["0", "1", "0", "1", "1", "0", "1", "0", "0", "0", "1", "0", "0", "1", "0", "0", "0", "0", "0", "1"],
290
+ // ["1", "0", "0", "1", "0", "1", "0", "0", "0", "1", "1", "0", "1", "0", "0", "1", "0", "0", "0", "0"],
291
+ // ["1", "0", "0", "0", "1", "1", "0", "0", "0", "0", "0", "1", "0", "0", "1", "0", "0", "0", "0", "1"],
292
+ // ["1", "0", "0", "0", "1", "0", "1", "1", "1", "0", "1", "0", "1", "1", "1", "1", "0", "0", "0", "1"],
293
+ // ["1", "0", "0", "1", "0", "0", "0", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1", "0", "1"],
294
+ // ["0", "0", "0", "1", "0", "1", "1", "1", "1", "1", "1", "1", "1", "1", "0", "0", "0", "0", "1", "0"],
295
+ // ["1", "0", "1", "0", "1", "0", "0", "1", "1", "1", "0", "1", "1", "0", "0", "1", "1", "0", "0", "0"],
296
+ // ["0", "1", "0", "0", "1", "0", "0", "0", "0", "0", "0", "1", "1", "1", "1", "0", "0", "0", "1", "0"],
297
+ // ["1", "0", "0", "0", "1", "1", "1", "0", "1", "0", "0", "0", "1", "0", "1", "0", "1", "0", "0", "1"],
298
+ // ["0", "0", "0", "0", "1", "0", "1", "1", "0", "1", "0", "1", "0", "1", "1", "1", "1", "0", "0", "0"],
299
+ // ["0", "1", "1", "0", "0", "0", "0", "1", "0", "0", "1", "1", "1", "0", "0", "1", "1", "0", "1", "0"],
300
+ // ["1", "0", "1", "1", "1", "1", "1", "1", "0", "1", "1", "0", "1", "0", "0", "1", "0", "0", "0", "1"],
301
+ // ["1", "0", "0", "0", "1", "0", "1", "0", "0", "1", "0", "1", "0", "0", "1", "0", "0", "1", "1", "1"],
302
+ // ["0", "0", "1", "0", "0", "0", "0", "1", "0", "0", "1", "1", "0", "1", "1", "1", "0", "0", "0", "0"],
303
+ // ["0", "0", "1", "0", "0", "0", "0", "0", "0", "1", "1", "0", "1", "0", "1", "0", "0", "0", "1", "1"],
304
+ // ["1", "0", "0", "0", "1", "0", "1", "1", "1", "0", "0", "1", "0", "1", "0", "1", "1", "0", "0", "0"]
305
+ // ])
0 commit comments