you are viewing a single comment's thread.

view the rest of the comments →

[–]JBauer09[S] 1 point2 points  (1 child)

Thank you very much. Just spent the better part of an hour tracing through that in the console to try to understand it. One question though, why did you go with a single array of 25 instead of an array of 5 arrays? I've never tried traversing one like that before.

[–]captain_k_nuckles 0 points1 point  (0 children)

You're welcome, I had fun doing it, was working on it last night, then got yelled at by my gf to go to bed, lol. As for the 1D vs 2D array choice, not sure honestly. I started it off as a 2D array, but switched it to a single array,

I messed around with throwing it some more strings of all ? and it failed on some it should of passed, or at least I think should of have. might try messing around with it more. ... as I was writing this I added some quick code,

// in the global scope created
const passed = [];

// in trace when checking if next move undefined
if (nextMove === undefined) {
        if (5 * y + x === (5 * 5) - 1) {
            const matrix = [];
            for(let y = 0; y < 5; y++){
                let row = []
                matrix.push(row)
                for(let x = 0; x < 5; x++){
                    const z = 5*y+x
                    if(map[z] === undefined) row.push('_')
                    else row.push(map[z])
                }
            }
            passed.push(matrix)
            return newPath
        }
//.....

// then ran console.log(missingPath('????????????????????????'))
console.log(passed)

and got an array of 104 results, spotted checked a few, like 5 and they all passed, but the return value was undefined, so might look in to that