Untitled
unknown
javascript
3 years ago
1.4 kB
3
Indexable
function SearchStack(stack, item) { var count = 0; let result = []; for (i = 0; i < stack.length; i++) { if (stack[i] != item) { result.push(stack[i]); } else if (stack[i] == item) { count += 1; } } if (count < 1) { return false; // return console.log(false); } else { return result; // return console.log(result); } } CheckGrid(arr) // Q6 // the input is going to be 4*4 array. // so that i can simply itereate ? // and every 2*2 array. I can take the values in one stack // then it can have same logical flow as q5 function CheckGrid(puzzle) { var st = []; let k = 1; for (i = 0; i < 3; i++) { console.log("check value i", i); for (j = 0; j < 3; j++) { console.log("check value i", i); console.log("check value j", j); st.push(puzzle[i][j]); st.push(puzzle[i][j + 1]); st.push(puzzle[i + 1][j]); st.push(puzzle[i + 1][j + 1]); for (k = 1; k <= 4; k++) { if (SearchStack(st, k) === false) { return console.log('false') } else { SearchStack(st, k); } } st = []; } } return console.log('true') }
Editor is loading...