This function calculates the sum of all the numbers in an array.
JavaScript:
let sum = arr => arr.reduce((a, b) => a + b, 0);
// Example
console.log(sum([1, 2, 3, 4, 5])); // 15
console.log(sum([10, 20, 30, 40])); // 100
TypeScript:
let sum = (arr: number[]): number => arr.reduce((a, b) => a + b, 0);
// Example
console.log(sum([1, 2, 3, 4, 5])); // 15
console.log(sum([10, 20, 30, 40])); // 100