I've been working on this 2D array and I'm facing an issue where I need to remove rows that have 5 or more instances of the number "one". I attempted to use the splice method (a.splice(j,1)), but it's not producing the desired result. I suspect this is because the splice method alters the overall row quantity, which in turn impacts the for loops.
Could it be a matter of incorrect usage of the splice method, or perhaps there's a better alternative method I should consider?
Thank you!
a = Array(7).fill(0).map(x => Array(10).fill(0))
for (let i = 0; i < 5; i++) {
a[1][i + 2] = 1;
a[4][i + 2] = 1;
a[5][i + 2] = 1;
}
console.log(a);
let count = 0;
for (let j = 0; j < 7; j++) {
for (let i = 0; i < 10; i++) {
if (a[j][i] == 1) {
count = count + 1;
}
}
if (count > 4) {
console.log("Line" + j);
// a.splice(j,1);
}
count = 0;
// a.splice(j,1);
}