Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x | /** * 計算數字陣列的總和 * @param numbers - 要計算總和的數字陣列 * * 範例: * 輸入: [1, 2, 3, 4, 5] * 輸出: 15 * * 輸入: [-1, -2, -3] * 輸出: -6 * * 輸入: [] * 輸出: 0 */ export function arraySum(numbers: number[]): number { // 在此實現函式 return numbers.reduce((sum, number) => sum + number, 0); } |