I am struggling with writing a function that extracts names from an array of tuples, where each tuple includes a name and an age. My current attempt looks like this:
type someTuple = [string, number]
function names(namesAndAges: someTuple[]) {
let allNames: string[]
allNames.push(namesAndAges.forEach( nameAndAge => nameAndAge[0]))
return allNames
}
However, when I test it with the following input:
names([['Amir', 34], ['Betty', 17]]);
I encounter the error message:
type error: type error: Variable 'allNames' is used before being assigned.
I'm unsure what's causing this issue. Any insights on what might be wrong?