FreeCodeCampChina / freecodecamp.cn

FCC China open source codebase and curriculum. Learn to code and help nonprofits.

Home Page:https://fcc.asia/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

我不太清楚这里的写法有没有问题,也不太清楚这要干嘛?可以解释下吗 ?谢谢

TOP-OWN opened this issue · comments

Challenge Record Collection has an issue.
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36.
Please describe how to reproduce this issue, and include links to screenshots if possible.

My code:

// 初始化变量
var collection = {
    2548: {
      album: "Slippery When Wet",
      artist: "Bon Jovi",
      tracks: [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    2468: {
      album: "1999",
      artist: "Prince",
      tracks: [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    1245: {
      artist: "Robert Palmer",
      tracks: [ ]
    },
    5439: {
      album: "ABBA Gold"
    }
};
// 深拷贝 collection,用于测试
var collectionCopy = JSON.parse(JSON.stringify(collection));

// 请只修改这条注释以下的代码
function update(id, prop, value) {
  if(value == ""){
    delete collectionCopy[id][prop];
  }else if(value !=''&& prop != 'tracks'){
    collectionCopy[id][prop]=value;
  }else if(value !=''&& prop == 'tracks'){
    collectionCopy[id][prop].push(value);
  }
  return collection;
}

// 你可以修改这一行来测试你的代码
update(5439, "artist", "ABBA");