FreeCodeCampChina / FreeCodeCampChina/freecodecamp.cn
我不太清楚这里的写法有没有问题,也不太清楚这要干嘛?可以解释下吗 ?谢谢
- Dominant language
- CSS
- Stars
- 37.8k
- Forks
- 1.4k
- PR merge metrics
- No merged PRs in 30d
Description
Challenge [Record Collection](https://www.freecodecamp.cn/challenges/record-collection#?solution=%2F%2F%20%E5%88%9D%E5%A7%8B%E5%8C%96%E5%8F%98%E9%87%8F%0Avar%20collection%20%3D%20%7B%0A%20%20%20%202548%3A%20%7B%0A%20%20%20%20%20%20album%3A%20%22Slippery%20When%20Wet%22%2C%0A%20%20%20%20%20%20artist%3A%20%22Bon%20Jovi%22%2C%0A%20%20%20%20%20%20tracks%3A%20%5B%20%0A%20%20%20%20%20%20%20%20%22Let%20It%20Rock%22%2C%20%0A%20%20%20%20%20%20%20%20%22You%20Give%20Love%20a%20Bad%20Name%22%20%0A%20%20%20%20%20%20%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%202468%3A%20%7B%0A%20%20%20%20%20%20album%3A%20%221999%22%2C%0A%20%20%20%20%20%20artist%3A%20%22Prince%22%2C%0A%20%20%20%20%20%20tracks%3A%20%5B%20%0A%20%20%20%20%20%20%20%20%221999%22%2C%20%0A%20%20%20%20%20%20%20%20%22Little%20Red%20Corvette%22%20%0A%20%20%20%20%20%20%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%201245%3A%20%7B%0A%20%20%20%20%20%20artist%3A%20%22Robert%20Palmer%22%2C%0A%20%20%20%20%20%20tracks%3A%20%5B%20%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%205439%3A%20%7B%0A%20%20%20%20%20%20album%3A%20%22ABBA%20Gold%22%0A%20%20%20%20%7D%0A%7D%3B%0A%2F%2F%20%E6%B7%B1%E6%8B%B7%E8%B4%9D%20collection%EF%BC%8C%E7%94%A8%E4%BA%8E%E6%B5%8B%E8%AF%95%0Avar%20collectionCopy%20%3D%20JSON.parse(JSON.stringify(collection))%3B%0A%0A%2F%2F%20%E8%AF%B7%E5%8F%AA%E4%BF%AE%E6%94%B9%E8%BF%99%E6%9D%A1%E6%B3%A8%E9%87%8A%E4%BB%A5%E4%B8%8B%E7%9A%84%E4%BB%A3%E7%A0%81%0Afunction%20update(id%2C%20prop%2C%20value)%20%7B%0A%20%20if(value%20%3D%3D%20%22%22)%7B%0A%20%20%20%20delete%20collectionCopy%5Bid%5D%5Bprop%5D%3B%0A%20%20%7Delse%20if(value%20!%3D''%26%26%20prop%20!%3D%20'tracks')%7B%0A%20%20%20%20collectionCopy%5Bid%5D%5Bprop%5D%3Dvalue%3B%0A%20%20%7Delse%20if(value%20!%3D''%26%26%20prop%20%3D%3D%20'tracks')%7B%0A%20%20%20%20collectionCopy%5Bid%5D%5Bprop%5D.push(value)%3B%0A%20%20%7D%0A%20%20return%20collection%3B%0A%7D%0A%0A%2F%2F%20%E4%BD%A0%E5%8F%AF%E4%BB%A5%E4%BF%AE%E6%94%B9%E8%BF%99%E4%B8%80%E8%A1%8C%E6%9D%A5%E6%B5%8B%E8%AF%95%E4%BD%A0%E7%9A%84%E4%BB%A3%E7%A0%81%0Aupdate(5439%2C%20%22artist%22%2C%20%22ABBA%22)%3B%0A%0A) 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:
```javascript
// 初始化变量
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");
```
Contributor guide
Research direction
Start with the linked Record Collection challenge and the shown update function, then determine which syntax or behavior the reporter wants explained. Done means the challenge or its surrounding guidance clearly explains the relevant code and expected result; the issue does not name a repository file or test to update.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- content
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100