fucking-algorithm icon indicating copy to clipboard operation
fucking-algorithm copied to clipboard

[bug][javascript] fi9suh

Open labuladong opened this issue 2 years ago • 1 comments

此 issue 的目的是修复 chatGPT 转译的多语言代码,更详细的背景信息和修复流程见:https://github.com/labuladong/fucking-algorithm/issues/1113

请在提交 bug 之前先搜索

  • [X] 我已经搜索过 issues,没有发现相同的 bug。

出错的题目链接

https://leetcode.cn/problems/fi9suh/

报错信息

Line 7: TypeError: this.calendar.floorKey is not a function
Line 7 in solution.js
    const earlier = this.calendar.floorKey(start);
                                  ^
TypeError: this.calendar.floorKey is not a function
    Line 7: Char 35 in solution.js (MyCalendar.book)
    Line 28: Char 26 in solution.js (helper_select_method)
    Line 69: Char 22 in solution.js (Object.<anonymous>)
    Line 16: Char 8 in runner.js (Object.runner)
    Line 23: Char 26 in solution.js (Object.<anonymous>)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
Result: 0/107 tests passed
Input: ["MyCalendar","book","book","book"],[[],[10,20],[15,25],[20,30]]
Expected: [null,true,false,true]

你是否愿意提交 PR 修复这个 bug?

  • [ ] 我愿意!

labuladong avatar Mar 26 '23 09:03 labuladong

It says that this.calendar.floorKey is not a function, hence it's either undefined, null or another datatype. I suggest you do something like this to avoid the issue

if (typeof this?.calendar?.floorKey === "function") this.calendar.floorKey()

onukwilip avatar Apr 13 '23 17:04 onukwilip