I am attempting to determine if a variable passed to a function, which can either be an array of numbers or an array of tuples, is the array of tuples.
function (times: Array<number> | Array<[number, number]>) {
if (Array.isArray(times[0]) && times[0].length === 2 && typeof times[0][0] === 'number' && typeof times[0][1] === 'number') {
console.log("It's the tuple one!");
}
}
The code above is not functioning as expected. I have also attempted using if (times[0] instanceof tuple))
, but that did not work either. Is there a way to achieve this?
Thank you!