I know there are a couple of answers on the matter, but as I was trying to make my own, I got very lost on how recursive functions work, here's what I tried :
function flatcoords(arr) {
for (i = 0; i < arr.length; i++) {
const value = arr[i];
if (value.isArray) {
return flatcoords(value);
} else {
return arr;
}
}
}
const arr_test = [
[
[1, 2],
[1, 2]
],
[1, 2],
[1, 2],
[
[
[1, 2],
[1, 2]
]
]
];
//wanted_result = [ [1,2],[1,2],[1,2],[1,2],[1,2],[1,2] ]
console.log(flatcoords(arr_test));
I want the result to be a 2D array, what am I missing in my logic?
[1, 2][? shouldn't there be a comma after]?