Tonyrj3268 / git-practice

0 stars 0 forks source link

Week 02 回饋 #2

Open azole opened 2 weeks ago

azole commented 2 weeks ago

readme

有觀察到版本號會包含很多小版本,很好。

sum

作業要求是以 array 函式來完成 sum,你選擇用 reduce,而不是其他 array 函式,為什麼?有研究過其他 array 函式嗎?為什麼不是選其他的?

Fib

你提供了兩種作法,本質上都是遞回,但第二種有用到 closure,請你分析一下第二種作法跟第一種作法的差異,有什麼優缺點?

Stack

Stack 這題做得很好,那我進一步想要跟你討論一下,有沒有可能讓 print 也能被測試(被 assert)?

Tonyrj3268 commented 1 week ago

作業要求是以 array 函式來完成 sum,你選擇用 reduce,而不是其他 array 函式,為什麼?有研究過其他 array 函式嗎?為什麼不是選其他的?

你提供了兩種作法,本質上都是遞回,但第二種有用到 closure,請你分析一下第二種作法跟第一種作法的差異,有什麼優缺點?

有沒有可能讓 print 也能被測試(被 assert)?

const logSpy = jest.spyOn(console, "log"); // 監視 console.log

console.log("5, 8"); // 調用 console.log

expect(logSpy).toHaveBeenCalled(); // 驗證 console.log 是否被調用
expect(logSpy).toHaveBeenCalledWith("5, 8"); // 驗證調用時的參數

logSpy.mockRestore(); // 恢復原始的 console.log