VSCode运行正常但TestDome JavaScript测试未通过,求问题排查
TestDome JavaScript 歌曲播放列表循环判断问题
这是一道TestDome的JavaScript测试题,判断规则如下:
- 若播放列表中任意歌曲指向列表中之前的歌曲,则视为循环播放列表
- 否则播放列表会以指向
undefined的最后一首歌曲结束
需要实现isRepeatingPlaylist方法,高效判断播放列表是否循环。
示例代码
let first = new Song("Hello"); let second = new Song("Eye of the tiger"); first.nextSong = second; second.nextSong = first; console.log(first.isRepeatingPlaylist());
该示例应输出
true
我的实现代码
class Song { name; nextSong; constructor(name) { this.name = name; } /** * @return {boolean} true if the playlist is repeating, false if not. */ isRepeatingPlaylist() { var newT = new Song(this.name) while (newT.nextSong = this.nextSong) { newT.nextSong = this.nextSong return true } return false } } let first = new Song("Hello"); let second = new Song("Eye of the tiger"); first.nextSong = second; second.nextSong = first; console.log(first.isRepeatingPlaylist());
测试结果
- 通过用例:示例用例
- 未通过用例:
- 循环播放列表中最后一首歌指向第一首:答案错误
- 循环播放列表可跳过起始歌曲:答案错误
- 大型播放列表性能测试:答案错误
此代码在VSCode中运行正常,但无法通过TestDome的上述测试,请问我遗漏了什么?
内容的提问来源于stack exchange,提问作者AMHF
相关产品推荐
相关产品推荐

