I have a function that returns to me [ '3000', '3001', '3002', '3003', '3004', '3005' ]
, where the elements within the array are generated from a range. So if I parse a line and find 3000-3005, I need to create each value in between that and return all of these values to be in a format of
ports: [ item, item, item, ...]
.
I have tried mapping over the individual values and returning them one by one, but obviously that only returns one value, is there a way to return everything individually? I've seen questions like Return multiple values in JavaScript?, but I need the returns to be dynamic since I won't know ahead of time the length, and I feel like I'm missing something.
edit: the structure of the code on a high-level is like this
return (
...
ports: functionCall(portArr)
...
)
functionCall(portArr) {
return (portArr.map((p) => {
if (typeof p === "string") {
const val = parsePorts(p);
return val;
}
return `${p.target}:${p.published}`;
});
}
Where the parsePorts function is where I determine what type of port structure it is and how to handle it and thats where the function below may be called.
function createRange(port: string, range: string) {
const ports = [];
for (let i = parseInt(port, 10); i <= parseInt(range, 10); i++) {
ports.push(`${i}`);
}
return ports;
}
So val
is potentially the array of my generated port ranges and from this function is where I need to return each value individually unpacked from the array