This function finds the index of the largest number in an array.
JavaScript:
let maxIndex = arr => arr.indexOf(Math.max(...arr));
// Example
console.log(maxIndex([10, 20, 30, 2, 50])); // 4
console.log(maxIndex([1.2, 0.2, 0.5, 1.1, 0.9])); // 0
TypeScript:
let maxIndex = (arr: number[]): number => arr.indexOf(Math.max(...arr));
// Example
console.log(maxIndex([10, 20, 30, 2, 50])); // 4
console.log(maxIndex([1.2, 0.2, 0.5, 1.1, 0.9])); // 0