All files arrayFiltering.ts

100% Statements 17/17
100% Branches 2/2
100% Functions 1/1
100% Lines 17/17

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 171x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 1x 1x 1x
/**
 * 任務:實作一個函式 `filterEvens`,過濾出數字陣列中的偶數。
 *
 * 範例:
 * filterEvens([1, 2, 3, 4]) 應該回傳 [2, 4]
 * filterEvens([5, 6, 7, 8]) 應該回傳 [6, 8]
 *
 * @param numbers - 一個需要被過濾的數字陣列
 * @returns - 回傳只包含偶數的數字陣列
 */
export function filterEvens(numbers: number[]): number[] {
    // 請在此處寫下你的程式碼
    return numbers.filter((n) => n % 2 === 0);
}
 
filterEvens([1, 2, 3, 4]);
filterEvens([5, 6, 7, 8]);