I am currently trying to make a Javascript function that will iterate through an array that represents 1 or more shapes in a nested array and each of these nested arrays could have a variable number of coordinates to create these shapes. At the bottom I have started the beginning of what this function could look like, but having trouble thinking out the logic.
Ex:
//This is a single 'shape' with 3 points
var coordsingle = [[1,1],[2,2],[3,3]];
//This one has 3 'shapes'
var coordmultiple = [[[1,1],[2,2],[3,3]],[[4,4],[5,5],[6,6],[7,7],[8,8]],[[-1,-1], [-2,-2],[-3,-3],[-4,-2],[-7,-3]]];
output:
coordsingle = 1 shape
1 - coordinates [1,1],[2,2],[3,3]
coordmultiple = 3 shapes
1 - coordinates [1,1],[2,2],[3,3]
2 - coordinates [4,4],[5,5],[6,6],[7,7],[8,8]
3 - coordinates [-1,-1], [-2,-2],[-3,-3],[-4,-2],[-7,-3]
function extractCoordinates(shapeArray){
let shapecount = data.length;
if(shapecount < 2){
document.write("<br>"," The Shape count is ",shapecount,"<br>");
document.write("<br>"," The amount of Coords ",data[0][0].length,"<br>");
document.write("<br>",data,"<br>");
}
else{
// this only outputs the first nested arrays set of coordinates
for(var coordpairs of shapecount){
document.write("<br>"," The Shape count is ",shapecount,"<br>");
document.write("<br>"," The amount of Coords ",data[0][0].length,"<br>");
document.write("<br>",data,"<br>");
}
}