I am working on a simple task where I have an array of shapes like square and rectangle and there sizes as another array passed as a parameter to function called findAllObjectArea
.
I want to return a promise from my function findAllObjectArea
which represents an array of areas of all my objects. Also inside my function, findObjectArea
I want to return promise which represents the area.
I have created below template but I am struggling to find out the correct syntax of it. Can you please help me on this.
let findObjectArea = (myobject, sizes) => {
new Promise(function(resolve, reject) {
if(myobject== 'square') {
resolve(sizes[0]*sizes[0]);
} else if(myobject== 'rectangle') {
resolve(sizes[0]*sizes[1]);
}
}
}
let findAllObjectArea = (objects, all_sizes) => {
new Promise((resolve, reject) => {
for(var i=0; i<objects.length; i++) {
findObjectArea (objects[i], all_sizes[i]);
}
);
}