Open neebz opened 4 years ago
Yes, if we push the single element to array and then for each element, call the requestTitle().But it will come with the cost of time complexity as even for a single element in array , it will go into for loop. I have chosen this solution , "if" concludes if the given parameters are in array , then for each element(param) in array call the function requestTitle() where as for a single param, just call requestTitle() not to trade time complexity.
const values= Array.isArray(request.query.address) ? request.query.address: [request.query.address] || [ ];
var arrayLength = values.length;
for (var counter = 0; counter < arrayLength; counter++) {
helper.requestTitle(values[counter], (title) => {
responseHelper.sendDescription(response, title);
});}
https://github.com/mahnoorfatima/Assignment-WebScrapper/blob/ec53d357002a0798e84cdf7cbdd3d3e37b3b0ff4/controller.js#L18
This code inside
else
and theif
is pretty much same except for thefor
loop. can you think of a way to reuse the code?