Kristofer Koishigawa b3213fc892 fix(i18n): chinese test suite (#38220)
* fix: Chinese test suite

Add localeTiltes, descriptions, and adjust test text and testStrings to get the automated test suite working.

* fix: ran script, updated testStrings and solutions
2020-03-03 18:49:47 +05:30

4.0 KiB
Raw Blame History

id, title, challengeType, videoUrl, localeTitle
id title challengeType videoUrl localeTitle
56533eb9ac21ba0edf2244cb Manipulating Complex Objects 1 操纵复杂对象

Description

有时您可能希望将数据存储在灵活的数据结构中 。 JavaScript对象是处理灵活数据的一种方法。它们允许字符串 数字 布尔值 数组 函数对象的任意组合。这是一个复杂数据结构的示例:
var ourMusic = [
{
“艺术家”“Daft Punk”
“标题”:“家庭作业”,
“release_year”1997年
“格式”:[
“光盘”,
“盒式”
“LP”
]
“黄金”:是的
}
]。
这是一个包含一个对象的数组。该对象具有关于专辑的各种元数据 。它还有一个嵌套的"formats"数组。如果要添加更多专辑记录,可以通过向顶级数组添加记录来完成此操作。对象将数据保存在属性中,该属性具有键值格式。在上面的示例中, "artist": "Daft Punk"是具有"artist"键和"Daft Punk"值的属性。 JavaScript Object NotationJSON是用于存储数据的相关数据交换格式。
{
“艺术家”“Daft Punk”
“标题”:“家庭作业”,
“release_year”1997年
“格式”:[
“光盘”,
“盒式”
“LP”
]
“黄金”:是的
}
注意
除非它是数组中的最后一个对象,否则您需要在数组中的每个对象后面放置一个逗号。

Instructions

将新相册添加到myMusic阵列。添加artisttitle字符串, release_year数字和formats字符串数组。

Tests

tests:
  - text: <code>myMusic</code>应该是一个数组
    testString: assert(Array.isArray(myMusic));
  - text: <code>myMusic</code>应该至少有两个元素
    testString: assert(myMusic.length > 1);
  - text: '<code>myMusic[1]</code>应该是一个对象'
    testString: assert(typeof myMusic[1] === 'object');
  - text: '<code>myMusic[1]</code>应该至少有4个属性'
    testString: assert(Object.keys(myMusic[1]).length > 3);
  - text: '<code>myMusic[1]</code>应该包含一个<code>artist</code>属性,它是一个字符串'
    testString: assert(myMusic[1].hasOwnProperty('artist') && typeof myMusic[1].artist === 'string');
  - text: '<code>myMusic[1]</code>应该包含一个<code>title</code>属性,它是一个字符串'
    testString: assert(myMusic[1].hasOwnProperty('title') && typeof myMusic[1].title === 'string');
  - text: '<code>myMusic[1]</code>应该包含一个<code>release_year</code>属性,它是一个数字'
    testString: assert(myMusic[1].hasOwnProperty('release_year') && typeof myMusic[1].release_year === 'number');
  - text: '<code>myMusic[1]</code>应该包含一个<code>formats</code>属性,它是一个数组'
    testString: assert(myMusic[1].hasOwnProperty('formats') && Array.isArray(myMusic[1].formats));
  - text: <code>formats</code>应该是一个至少包含两个元素的字符串数组
    testString: assert(myMusic[1].formats.every(function(item) { return (typeof item === "string")}) && myMusic[1].formats.length > 1);

Challenge Seed

var myMusic = [
  {
    "artist": "Billy Joel",
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [
      "CD",
      "8T",
      "LP"
    ],
    "gold": true
  }
  // Add record here
];

After Test

console.info('after the test');

Solution

// solution required