I need some help refining my function that is designed to identify the index of the largest number in an array. Unfortunately, my current implementation breaks when it encounters negative numbers within the array. Here's the code snippet I've been working on:
export let maxIndex = (a: number[]): number => {
let biggest = -9000000000; // Used to track the largest element
if (a.length === 0) {
return -1;
} else {
for (let i = 0; i < a.length; i++) {
if (a[i] > biggest) {
biggest = a[i];
}
}
}
return a[biggest];
};