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 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x | /**
* 將兩個數字相加
* @param a - 第一個數字
* @param b - 第二個數字
*/
export function add(a: number, b: number): number {
// 在此實現函式
return a + b;
}
/**
* 將兩個數字相減
* @param a - 第一個數字
* @param b - 第二個數字
*/
export function subtract(a: number, b: number): number {
// 在此實現函式
return a - b;
}
/**
* 將兩個數字相乘
* @param a - 第一個數字
* @param b - 第二個數字
*/
export function multiply(a: number, b: number): number {
// 在此實現函式
return a * b;
}
/**
* 將兩個數字相除
* @param a - 第一個數字
* @param b - 第二個數字
*/
export function divide(a: number, b: number): number {
// 在此實現函式
// #NOTES: 除法函數應該拋出錯誤,當嘗試除以零時
if (b === 0) {
throw new Error("Cannot divide by zero");
}
return a / b;
}
/**
* 實現加法函數,結果不能超過 100。
*
* @param a 第一個加數。
* @param b 第二個加數。
* @returns 兩個數字的和,但不超過 100。
*/
export function add100(a: number, b: number): number {
const sum = a + b;
return sum > 100 ? 100 : sum;
} |