You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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());

测试结果

  • 通过用例:示例用例
  • 未通过用例:
    1. 循环播放列表中最后一首歌指向第一首:答案错误
    2. 循环播放列表可跳过起始歌曲:答案错误
    3. 大型播放列表性能测试:答案错误

此代码在VSCode中运行正常,但无法通过TestDome的上述测试,请问我遗漏了什么?


内容的提问来源于stack exchange,提问作者AMHF

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 23:15:42