* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
3.3 KiB
3.3 KiB
id, title, challengeType, videoUrl, forumTopicId, dashedName
id | title | challengeType | videoUrl | forumTopicId | dashedName |
---|---|---|---|---|---|
5688e62ea601b2482ff8422b | 资料查找 | 1 | https://scrimba.com/c/cDqW2Cg | 18259 | profile-lookup |
--description--
我们有一个对象数组,里面存储着通讯录。
函数lookUp
有两个预定义参数:firstName
值和prop
属性 。
函数将会检查通讯录中是否存在一个与传入的firstName
相同的联系人。如果存在,那么还需要检查对应的联系人中是否存在prop
属性。
如果它们都存在,函数返回prop
属性对应的值。
如果firstName
值不存在,返回"No such contact"
。
如果prop
属性不存在,返回"No such property"
。
--hints--
"Kristian", "lastName"
应该返回 "Vos"
。
assert(lookUpProfile('Kristian', 'lastName') === 'Vos');
"Sherlock", "likes"
应该返回 ["Intriguing Cases", "Violin"]
。
assert.deepEqual(lookUpProfile('Sherlock', 'likes'), [
'Intriguing Cases',
'Violin'
]);
"Harry","likes"
应该返回 an array。
assert(typeof lookUpProfile('Harry', 'likes') === 'object');
"Bob", "number"
应该返回 "No such contact"。
assert(lookUpProfile('Bob', 'number') === 'No such contact');
"Bob", "potato"
应该返回 "No such contact"。
assert(lookUpProfile('Bob', 'potato') === 'No such contact');
"Akira", "address"
应该返回 "No such property"。
assert(lookUpProfile('Akira', 'address') === 'No such property');
--seed--
--seed-contents--
// Setup
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
"lastName": "Potter",
"number": "0994372684",
"likes": ["Hogwarts", "Magic", "Hagrid"]
},
{
"firstName": "Sherlock",
"lastName": "Holmes",
"number": "0487345643",
"likes": ["Intriguing Cases", "Violin"]
},
{
"firstName": "Kristian",
"lastName": "Vos",
"number": "unknown",
"likes": ["JavaScript", "Gaming", "Foxes"]
}
];
function lookUpProfile(name, prop){
// Only change code below this line
// Only change code above this line
}
lookUpProfile("Akira", "likes");
--solutions--
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
"lastName": "Potter",
"number": "0994372684",
"likes": ["Hogwarts", "Magic", "Hagrid"]
},
{
"firstName": "Sherlock",
"lastName": "Holmes",
"number": "0487345643",
"likes": ["Intriguing Cases", "Violin"]
},
{
"firstName": "Kristian",
"lastName": "Vos",
"number": "unknown",
"likes": ["JavaScript", "Gaming", "Foxes"]
},
];
//Write your function in between these comments
function lookUpProfile(name, prop){
for(var i in contacts){
if(contacts[i].firstName === name) {
return contacts[i][prop] || "No such property";
}
}
return "No such contact";
}
//Write your function in between these comments
lookUpProfile("Akira", "likes");