I have a Google Sheets script that is supposed to grab data from an API but I am getting the error
TypeError: Cannot read property 'length' of undefined (line 5, file "draftOrder")
How can I fix this error? I haven't touched this script in years, so I'm not sure what broke.
function draftOrder(ownerRange, numRounds) {
var output = [];
var owners = [];
for (var i = 0; i < ownerRange.length; i++) {
if (ownerRange[i][0] !== '') {
owners.push(ownerRange[i][0]);
}
}
for (var i = 0; i < numRounds; i++) {
if (i % 2 == 0) {
output = output.concat(owners);
} else {
output = output.concat([].concat(owners).reverse());
}
}
return output;
}
Thanks in advance for any help that you can provide. Cheers!