All files todoInterface.ts

100% Statements 33/33
100% Branches 1/1
100% Functions 1/1
100% Lines 33/33

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 341x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x  
/**
 * 待辦事項介面已被移除,你需要自己定義一個新的待辦事項介面。
 * 待辦事項介面應該包含 id、task 和 completed 三個屬性,分別為數字型別、字串型別和布林型別。
 */
 
/**
 * 新增待辦事項
 * @param todos - 現有的待辦事項陣列
 * @param task - 新的待辦事項的內容
 * 
 * 範例:
 * 輸入: ([{ id: 1, task: 'Buy milk', completed: false }], 'Walk the dog')
 * 輸出: [{ id: 1, task: 'Buy milk', completed: false }, { id: 2, task: 'Walk the dog', completed: false }]
 */
 
type Todo = {
    id: number;
    task: string;
    completed: boolean;
}
 
export function addTodo(todos: Todo[], task: string): Todo[] {
    // 在此實現函式
    const newTodo = {
        id: todos.length + 1,
        task,
        completed: false
    };
 
    return [...todos, newTodo];
}
 
addTodo([{ id: 1, task: 'Buy milk', completed: false }], 'Walk the dog');