diff --git a/08-coding-interview-prep/algorithms.json b/08-coding-interview-prep/algorithms.json
index 7f1dcb8..77ccf94 100644
--- a/08-coding-interview-prep/algorithms.json
+++ b/08-coding-interview-prep/algorithms.json
@@ -8,69 +8,70 @@
"id": "a3f503de51cf954ede28891d",
"title": "Find the Symmetric Difference",
"description": [
- "Create a function that takes two or more arrays and returns an array of the symmetric difference (△ or ⊕) of the provided arrays.",
- "Given two sets (for example set A = {1, 2, 3} and set B = {2, 3, 4}), the mathematical term \"symmetric difference\" of two sets is the set of elements which are in either of the two sets, but not in both (A △ B = C = {1, 4}). For every additional symmetric difference you take (say on a set D = {2, 3}), you should get the set with elements which are in either of the two the sets but not both (C △ D = {1, 4} △ {2, 3} = {1, 2, 3, 4}). The resulting array must contain only unique values (no duplicates).",
- "Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code."
+ "知识提要:对称差 (Symmetric Difference),数学上,两个集合的对称差分是只属于其中一个集合,而不属于另一个集合的元素组成的集合,例如:集合let A = [ 1, 2, 3]和let B = [ 2, 3, 4]的对称差分为A △ B = C = [ 1, 4]。 集合论中的这个运算相当于布尔逻辑中的异或运算。",
+ "创建一个函数 sym,输入两个或两个以上的数组作为参数,然后返回值为对称差分的数组",
+ "思路:设定两个数组 (例如:let A = [1, 2, 3],let B = [2, 3, 4])作为参数传入,返回对称差分数组(A △ B = C = [1, 4]),且数组中没有重复项。",
+ "如果你遇到了困难,请点击帮助。你可以找人“结对编程”,但不要因此放弃思考。",
],
"solutions": [
"function sym() {\n var arrays = [].slice.call(arguments);\n return arrays.reduce(function (symDiff, arr) {\n return symDiff.concat(arr).filter(function (val, idx, theArr) {\n return theArr.indexOf(val) === idx \n && (symDiff.indexOf(val) === -1 || arr.indexOf(val) === -1);\n });\n });\n}\nsym([1, 2, 3], [5, 2, 1, 4]);\n"
],
"tests": [
{
- "text": "sym([1, 2, 3], [5, 2, 1, 4]) should return [3, 4, 5].",
- "testString": "assert.sameMembers(sym([1, 2, 3], [5, 2, 1, 4]), [3, 4, 5], 'sym([1, 2, 3], [5, 2, 1, 4]) should return [3, 4, 5].');"
+ "text": "sym([1, 2, 3], [5, 2, 1, 4])应该返回< code>[3, 4, 5]。",
+ "testString": "assert.sameMembers(sym([1, 2, 3], [5, 2, 1, 4]), [3, 4, 5],'sym([1, 2, 3], [5, 2, 1, 4])应该返回[3, 4, 5]。');"
},
{
- "text": "sym([1, 2, 3], [5, 2, 1, 4]) should contain only three elements.",
- "testString": "assert.equal(sym([1, 2, 3], [5, 2, 1, 4]).length, 3, 'sym([1, 2, 3], [5, 2, 1, 4]) should contain only three elements.');"
+ "text": "sym([1, 2, 3], [5, 2, 1, 4])的返回值应该只包含三个元素。",
+ "testString": "assert.equal(sym([1, 2, 3], [5, 2, 1, 4]).length, 3,'sym([1, 2, 3], [5, 2, 1, 4])的返回值应该只包含三个元素。');"
},
{
- "text": "sym([1, 2, 3, 3], [5, 2, 1, 4]) should return [3, 4, 5].",
- "testString": "assert.sameMembers(sym([1, 2, 3, 3], [5, 2, 1, 4]), [3, 4, 5], 'sym([1, 2, 3, 3], [5, 2, 1, 4]) should return [3, 4, 5].');"
+ "text": "sym([1, 2, 3, 3], [5, 2, 1, 4])应该返回[3, 4, 5]。",
+ "testString": "assert.sameMembers(sym([1, 2, 3, 3], [5, 2, 1, 4]), [3, 4, 5],'sym([1, 2, 3, 3], [5, 2, 1, 4])应该返回[3, 4, 5]。');"
},
{
- "text": "sym([1, 2, 3, 3], [5, 2, 1, 4]) should contain only three elements.",
- "testString": "assert.equal(sym([1, 2, 3, 3], [5, 2, 1, 4]).length, 3, 'sym([1, 2, 3, 3], [5, 2, 1, 4]) should contain only three elements.');"
+ "text": "sym([1, 2, 3, 3], [5, 2, 1, 4])返回的数组应该只包含三个元素",
+ "testString": "assert.equal(sym([1, 2, 3, 3], [5, 2, 1, 4]).length, 3,'sym([1, 2, 3, 3], [5, 2, 1, 4])返回的数组应该只包含三个元素。');"
},
{
- "text": "sym([1, 2, 3], [5, 2, 1, 4, 5]) should return [3, 4, 5].",
- "testString": "assert.sameMembers(sym([1, 2, 3], [5, 2, 1, 4, 5]), [3, 4, 5], 'sym([1, 2, 3], [5, 2, 1, 4, 5]) should return [3, 4, 5].');"
+ "text": "sym([1, 2, 3], [5, 2, 1, 4, 5])应该返回[3, 4, 5]。",
+ "testString": "assert.sameMembers(sym([1, 2, 3], [5, 2, 1, 4, 5]), [3, 4, 5],'sym([1, 2, 3], [5, 2, 1, 4, 5])应该返回[3, 4, 5]。');"
},
{
- "text": "sym([1, 2, 3], [5, 2, 1, 4, 5]) should contain only three elements.",
- "testString": "assert.equal(sym([1, 2, 3], [5, 2, 1, 4, 5]).length, 3, 'sym([1, 2, 3], [5, 2, 1, 4, 5]) should contain only three elements.');"
+ "text": "sym([1, 2, 3], [5, 2, 1, 4, 5])返回的数组应该只包含三个元素。",
+ "testString": "assert.equal(sym([1, 2, 3], [5, 2, 1, 4, 5]).length, 3,'sym([1, 2, 3], [5, 2, 1, 4, 5])返回的数组应该只包含三个元素。');"
},
{
- "text": "sym([1, 2, 5], [2, 3, 5], [3, 4, 5]) should return [1, 4, 5]",
- "testString": "assert.sameMembers(sym([1, 2, 5], [2, 3, 5], [3, 4, 5]), [1, 4, 5], 'sym([1, 2, 5], [2, 3, 5], [3, 4, 5]) should return [1, 4, 5]');"
+ "text": "sym([1, 2, 5], [2, 3, 5], [3, 4, 5])应该返回[1, 4, 5]。",
+ "testString": "assert.sameMembers(sym([1, 2, 5], [2, 3, 5], [3, 4, 5]), [1, 4, 5],'sym([1, 2, 5], [2, 3, 5], [3, 4, 5])应该返回[1, 4, 5]。');"
},
{
- "text": "sym([1, 2, 5], [2, 3, 5], [3, 4, 5]) should contain only three elements.",
- "testString": "assert.equal(sym([1, 2, 5], [2, 3, 5], [3, 4, 5]).length, 3, 'sym([1, 2, 5], [2, 3, 5], [3, 4, 5]) should contain only three elements.');"
+ "text": "sym([1, 2, 5], [2, 3, 5], [3, 4, 5])返回的数组应该只包含三个元素。",
+ "testString": "assert.equal(sym([1, 2, 5], [2, 3, 5], [3, 4, 5]).length, 3,'sym([1, 2, 5], [2, 3, 5], [3, 4, 5])返回的数组应该只包含三个元素。');"
},
{
- "text": "sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]) should return [1, 4, 5].",
- "testString": "assert.sameMembers(sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]), [1, 4, 5], 'sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]) should return [1, 4, 5].');"
+ "text": "sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])应该返回[1, 4, 5]。",
+ "testString": "assert.sameMembers(sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]), [1, 4, 5],'sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])应该返回[1, 4, 5]。');"
},
{
- "text": "sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]) should contain only three elements.",
- "testString": "assert.equal(sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]).length, 3, 'sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]) should contain only three elements.');"
+ "text": "sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])返回的数组应该只包含三个元素。",
+ "testString": "assert.equal(sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]).length, 3,'sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])返回的数组应该只包含三个元素。');"
},
{
- "text": "sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3]) should return [2, 3, 4, 6, 7].",
- "testString": "assert.sameMembers(sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3]), [2, 3, 4, 6, 7], 'sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3]) should return [2, 3, 4, 6, 7].');"
+ "text": "sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3])应该返回[2, 3, 4, 6, 7]。",
+ "testString": "assert.sameMembers(sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3]), [2, 3, 4, 6, 7],'sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3]) 应该返回 [2, 3, 4, 6, 7]。');"
},
{
- "text": "sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3]) should contain only five elements.",
- "testString": "assert.equal(sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3]).length, 5, 'sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3]) should contain only five elements.');"
+ "text": "sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3])返回的数组应该只包含五个元素。",
+ "testString": "assert.equal(sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3]).length, 5,'sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3])返回的数组应该只包含五个元素。');"
},
{
- "text": "sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1]) should return [1, 2, 4, 5, 6, 7, 8, 9].",
- "testString": "assert.sameMembers(sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1]), [1, 2, 4, 5, 6, 7, 8, 9], 'sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1]) should return [1, 2, 4, 5, 6, 7, 8, 9].');"
+ "text": "sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1])应该返回[1, 2, 4, 5, 6, 7, 8, 9]。",
+ "testString": "assert.sameMembers(sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1]), [1, 2, 4, 5, 6, 7, 8, 9],'sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1])应该返回[1, 2, 4, 5, 6, 7, 8, 9]。');"
},
{
- "text": "sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1]) should contain only eight elements.",
- "testString": "assert.equal(sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1]).length, 8, 'sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1]) should contain only eight elements.');"
+ "text": "sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1])返回的数组应该只包含八个元素。",
+ "testString": "assert.equal(sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1]).length, 8,'sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1])返回的数组应该只包含八个元素。');"
}
],
"MDNlinks": [
@@ -99,36 +100,36 @@
"id": "a56138aff60341a09ed6c480",
"title": "Inventory Update",
"description": [
- "Compare and update the inventory stored in a 2D array against a second 2D array of a fresh delivery. Update the current existing inventory item quantities (in arr1). If an item cannot be found, add the new item and quantity into the inventory array. The returned inventory array should be in alphabetical order by item.",
- "Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code."
+ "创建一个二维数组,比较并更新存储在二维数组中的 ”库存“ 元素,然后并将其与新产生的第二个二维数组进行对比,更新当前的 ”库存“ 项的数量(arr1),如果找不到这个对比对象,那么将新的对象和数量添加到 “库存” 数组中。注意:返回的 “库存” 数组应该是按照数组元素的首字母顺序排序",
+ "如果你遇到了困难,请点击帮助。你可以找人“结对编程“,但不要因此放弃思考。",
],
"solutions": [
- "function updateInventory(arr1, arr2) {\n arr2.forEach(function(item) {\n createOrUpdate(arr1, item);\n });\n // All inventory must be accounted for or you're fired!\n return arr1;\n}\n\nfunction createOrUpdate(arr1, item) {\n var index = -1;\n while (++index < arr1.length) {\n if (arr1[index][1] === item[1]) {\n arr1[index][0] += item[0];\n return;\n }\n if (arr1[index][1] > item[1]) {\n break;\n }\n }\n arr1.splice(index, 0, item);\n}\n\n// Example inventory lists\nvar curInv = [\n [21, 'Bowling Ball'],\n [2, 'Dirty Sock'],\n [1, 'Hair Pin'],\n [5, 'Microphone']\n];\n\nvar newInv = [\n [2, 'Hair Pin'],\n [3, 'Half-Eaten Apple'],\n [67, 'Bowling Ball'],\n [7, 'Toothpaste']\n];\n\nupdateInventory(curInv, newInv);\n"
+ "function updateInventory(arr1, arr2) {\n arr2.forEach(function(item) {\n createOrUpdate(arr1, item);\n });\n // 所有的存货都必须记帐,否则你将被解雇!\n return arr1;\n}\n\nfunction createOrUpdate(arr1, item) {\n var index = -1;\n while (++index < arr1.length) {\n if (arr1[index][1] === item[1]) {\n arr1[index][0] += item[0];\n return;\n }\n if (arr1[index][1] > item[1]) {\n break;\n }\n }\n arr1.splice(index, 0, item);\n}\n\n// 示例库存列表 \nvar curInv = [\n [21,'Bowling Ball'],\n [2,'Dirty Sock'],\n [1,'Hair Pin'],\n [5,'Microphone']\n];\n\nvar newInv = [\n [2,'Hair Pin'],\n [3,'Half-Eaten Apple'],\n [67,'Bowling Ball'],\n [7,'Toothpaste']\n];\n\nupdateInventory(curInv, newInv);\n"
],
"tests": [
{
- "text": "The function updateInventory should return an array.",
- "testString": "assert.isArray(updateInventory([[21, \"Bowling Ball\"], [2, \"Dirty Sock\"], [1, \"Hair Pin\"], [5, \"Microphone\"]], [[2, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [67, \"Bowling Ball\"], [7, \"Toothpaste\"]]), 'The function updateInventory should return an array.');"
+ "text": "函数updateInventory应该返回一个数组。",
+ "testString": "assert.isArray(updateInventory([[21, \"Bowling Ball\"], [2, \"Dirty Sock\"], [1, \"Hair Pin\"], [5, \"Microphone\"]], [[2, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [67, \"Bowling Ball\"], [7, \"Toothpaste\"]]),'函数updateInventory应该返回一个数组。');"
},
{
- "text": "updateInventory([[21, \"Bowling Ball\"], [2, \"Dirty Sock\"], [1, \"Hair Pin\"], [5, \"Microphone\"]], [[2, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [67, \"Bowling Ball\"], [7, \"Toothpaste\"]]) should return an array with a length of 6.",
- "testString": "assert.equal(updateInventory([[21, \"Bowling Ball\"], [2, \"Dirty Sock\"], [1, \"Hair Pin\"], [5, \"Microphone\"]], [[2, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [67, \"Bowling Ball\"], [7, \"Toothpaste\"]]).length, 6, 'updateInventory([[21, \"Bowling Ball\"], [2, \"Dirty Sock\"], [1, \"Hair Pin\"], [5, \"Microphone\"]], [[2, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [67, \"Bowling Ball\"], [7, \"Toothpaste\"]]) should return an array with a length of 6.');"
+ "text": "updateInventory([[21, \"Bowling Ball\"], [2, \"Dirty Sock\"], [1, \"Hair Pin\"], [5, \"Microphone\"]], [[2, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [67, \"Bowling Ball\"], [7, \"Toothpaste\"]])返回的数组长度应该为 6。",
+ "testString": "assert.equal(updateInventory([[21, \"Bowling Ball\"], [2, \"Dirty Sock\"], [1, \"Hair Pin\"], [5, \"Microphone\"]], [[2, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [67, \"Bowling Ball\"], [7, \"Toothpaste\"]]).length, 6,'updateInventory([[21, \"Bowling Ball\"], [2, \"Dirty Sock\"], [1, \"Hair Pin\"], [5, \"Microphone\"]], [[2, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [67, \"Bowling Ball\"], [7, \"Toothpaste\"]])应该返回一个长度为 6 的数组。');"
},
{
- "text": "updateInventory([[21, \"Bowling Ball\"], [2, \"Dirty Sock\"], [1, \"Hair Pin\"], [5, \"Microphone\"]], [[2, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [67, \"Bowling Ball\"], [7, \"Toothpaste\"]]) should return [[88, \"Bowling Ball\"], [2, \"Dirty Sock\"], [3, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [5, \"Microphone\"], [7, \"Toothpaste\"]].",
- "testString": "assert.deepEqual(updateInventory([[21, \"Bowling Ball\"], [2, \"Dirty Sock\"], [1, \"Hair Pin\"], [5, \"Microphone\"]], [[2, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [67, \"Bowling Ball\"], [7, \"Toothpaste\"]]), [[88, \"Bowling Ball\"], [2, \"Dirty Sock\"], [3, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [5, \"Microphone\"], [7, \"Toothpaste\"]], 'updateInventory([[21, \"Bowling Ball\"], [2, \"Dirty Sock\"], [1, \"Hair Pin\"], [5, \"Microphone\"]], [[2, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [67, \"Bowling Ball\"], [7, \"Toothpaste\"]]) should return [[88, \"Bowling Ball\"], [2, \"Dirty Sock\"], [3, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [5, \"Microphone\"], [7, \"Toothpaste\"]].');"
+ "text": "updateInventory([[21, \"Bowling Ball\"], [2, \"Dirty Sock\"], [1, \"Hair Pin\"], [5, \"Microphone\"]], [[2, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [67, \"Bowling Ball\"], [7, \"Toothpaste\"]])应该返回[[88, \"Bowling Ball\"], [2, \"Dirty Sock\"], [3, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [5, \"Microphone\"], [7, \"Toothpaste\"]]。",
+ "testString": "assert.deepEqual(updateInventory([[21, \"Bowling Ball\"], [2, \"Dirty Sock\"], [1, \"Hair Pin\"], [5, \"Microphone\"]], [[2, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [67, \"Bowling Ball\"], [7, \"Toothpaste\"]]), [[88, \"Bowling Ball\"], [2, \"Dirty Sock\"], [3, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [5, \"Microphone\"], [7, \"Toothpaste\"]],'updateInventory([[21, \"Bowling Ball\"], [2, \"Dirty Sock\"], [1, \"Hair Pin\"], [5, \"Microphone\"]], [[2, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [67, \"Bowling Ball\"], [7, \"Toothpaste\"]])应该返回[[88, \"Bowling Ball\"], [2, \"Dirty Sock\"], [3, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [5, \"Microphone\"], [7, \"Toothpaste\"]]。');"
},
{
- "text": "updateInventory([[21, \"Bowling Ball\"], [2, \"Dirty Sock\"], [1, \"Hair Pin\"], [5, \"Microphone\"]], []) should return [[21, \"Bowling Ball\"], [2, \"Dirty Sock\"], [1, \"Hair Pin\"], [5, \"Microphone\"]].",
- "testString": "assert.deepEqual(updateInventory([[21, \"Bowling Ball\"], [2, \"Dirty Sock\"], [1, \"Hair Pin\"], [5, \"Microphone\"]], []), [[21, \"Bowling Ball\"], [2, \"Dirty Sock\"], [1, \"Hair Pin\"], [5, \"Microphone\"]], 'updateInventory([[21, \"Bowling Ball\"], [2, \"Dirty Sock\"], [1, \"Hair Pin\"], [5, \"Microphone\"]], []) should return [[21, \"Bowling Ball\"], [2, \"Dirty Sock\"], [1, \"Hair Pin\"], [5, \"Microphone\"]].');"
+ "text": "updateInventory([[21, \"Bowling Ball\"], [2, \"Dirty Sock\"], [1, \"Hair Pin\"], [5, \"Microphone\"]], [])应该返回[[21, \"Bowling Ball\"], [2, \"Dirty Sock\"], [1, \"Hair Pin\"], [5, \"Microphone\"]]。",
+ "testString": "assert.deepEqual(updateInventory([[21, \"Bowling Ball\"], [2, \"Dirty Sock\"], [1, \"Hair Pin\"], [5, \"Microphone\"]], []), [[21, \"Bowling Ball\"], [2, \"Dirty Sock\"], [1, \"Hair Pin\"], [5, \"Microphone\"]],'updateInventory([[21, \"Bowling Ball\"], [2, \"Dirty Sock\"], [1, \"Hair Pin\"], [5, \"Microphone\"]], [])应该返回[[21, \"Bowling Ball\"], [2, \"Dirty Sock\"], [1, \"Hair Pin\"], [5, \"Microphone\"]]。');"
},
{
- "text": "updateInventory([], [[2, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [67, \"Bowling Ball\"], [7, \"Toothpaste\"]]) should return [[67, \"Bowling Ball\"], [2, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [7, \"Toothpaste\"]].",
- "testString": "assert.deepEqual(updateInventory([], [[2, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [67, \"Bowling Ball\"], [7, \"Toothpaste\"]]), [[67, \"Bowling Ball\"], [2, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [7, \"Toothpaste\"]], 'updateInventory([], [[2, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [67, \"Bowling Ball\"], [7, \"Toothpaste\"]]) should return [[67, \"Bowling Ball\"], [2, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [7, \"Toothpaste\"]].');"
+ "text": "updateInventory([], [[2, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [67, \"Bowling Ball\"], [7, \"Toothpaste\"]])应该返回[[67, \"Bowling Ball\"], [2, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [7, \"Toothpaste\"]]。",
+ "testString": "assert.deepEqual(updateInventory([], [[2, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [67, \"Bowling Ball\"], [7, \"Toothpaste\"]]), [[67, \"Bowling Ball\"], [2, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [7, \"Toothpaste\"]],'updateInventory([], [[2, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [67, \"Bowling Ball\"], [7, \"Toothpaste\"]])应该返回[[67, \"Bowling Ball\"], [2, \"Hair Pin\"], [3, \"Half-Eaten Apple\"], [7, \"Toothpaste\"]]。');"
},
{
- "text": "updateInventory([[0, \"Bowling Ball\"], [0, \"Dirty Sock\"], [0, \"Hair Pin\"], [0, \"Microphone\"]], [[1, \"Hair Pin\"], [1, \"Half-Eaten Apple\"], [1, \"Bowling Ball\"], [1, \"Toothpaste\"]]) should return [[1, \"Bowling Ball\"], [0, \"Dirty Sock\"], [1, \"Hair Pin\"], [1, \"Half-Eaten Apple\"], [0, \"Microphone\"], [1, \"Toothpaste\"]].",
- "testString": "assert.deepEqual(updateInventory([[0, \"Bowling Ball\"], [0, \"Dirty Sock\"], [0, \"Hair Pin\"], [0, \"Microphone\"]], [[1, \"Hair Pin\"], [1, \"Half-Eaten Apple\"], [1, \"Bowling Ball\"], [1, \"Toothpaste\"]]), [[1, \"Bowling Ball\"], [0, \"Dirty Sock\"], [1, \"Hair Pin\"], [1, \"Half-Eaten Apple\"], [0, \"Microphone\"], [1, \"Toothpaste\"]], 'updateInventory([[0, \"Bowling Ball\"], [0, \"Dirty Sock\"], [0, \"Hair Pin\"], [0, \"Microphone\"]], [[1, \"Hair Pin\"], [1, \"Half-Eaten Apple\"], [1, \"Bowling Ball\"], [1, \"Toothpaste\"]]) should return [[1, \"Bowling Ball\"], [0, \"Dirty Sock\"], [1, \"Hair Pin\"], [1, \"Half-Eaten Apple\"], [0, \"Microphone\"], [1, \"Toothpaste\"]].');"
+ "text": "updateInventory([[0, \"Bowling Ball\"], [0, \"Dirty Sock\"], [0, \"Hair Pin\"], [0, \"Microphone\"]], [[1, \"Hair Pin\"], [1, \"Half-Eaten Apple\"], [1, \"Bowling Ball\"], [1, \"Toothpaste\"]])应该返回[[1, \"Bowling Ball\"], [0, \"Dirty Sock\"], [1, \"Hair Pin\"], [1, \"Half-Eaten Apple\"], [0, \"Microphone\"], [1, \"Toothpaste\"]]。",
+ "testString": "assert.deepEqual(updateInventory([[0, \"Bowling Ball\"], [0, \"Dirty Sock\"], [0, \"Hair Pin\"], [0, \"Microphone\"]], [[1, \"Hair Pin\"], [1, \"Half-Eaten Apple\"], [1, \"Bowling Ball\"], [1, \"Toothpaste\"]]), [[1, \"Bowling Ball\"], [0, \"Dirty Sock\"], [1, \"Hair Pin\"], [1, \"Half-Eaten Apple\"], [0, \"Microphone\"], [1, \"Toothpaste\"]],'updateInventory([[0, \"Bowling Ball\"], [0, \"Dirty Sock\"], [0, \"Hair Pin\"], [0, \"Microphone\"]], [[1, \"Hair Pin\"], [1, \"Half-Eaten Apple\"], [1, \"Bowling Ball\"], [1, \"Toothpaste\"]]) 应该返回 [[1, \"Bowling Ball\"], [0, \"Dirty Sock\"], [1, \"Hair Pin\"], [1, \"Half-Eaten Apple\"], [0, \"Microphone\"], [1, \"Toothpaste\"]]。');"
}
],
"MDNlinks": [
@@ -142,11 +143,11 @@
"name": "index",
"contents": [
"function updateInventory(arr1, arr2) {",
- " // All inventory must be accounted for or you're fired!",
+ "// 所有的存货都必须记帐,否则你将被解雇!",
" return arr1;",
"}",
"",
- "// Example inventory lists",
+ "// 两个货物列表示例",
"var curInv = [",
" [21, \"Bowling Ball\"],",
" [2, \"Dirty Sock\"],",
@@ -172,53 +173,53 @@
"id": "a7bf700cd123b9a54eef01d5",
"title": "No Repeats Please",
"description": [
- "Return the number of total permutations of the provided string that don't have repeated consecutive letters. Assume that all characters in the provided string are each unique.",
- "For example, aab should return 2 because it has 6 total permutations (aab, aab, aba, aba, baa, baa), but only 2 of them (aba and aba) don't have the same letter (in this case a) repeating.",
- "Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code."
+ "把一个字符串中的字符重新排列生成新的字符串,返回新生成的字符串里没有连续重复字符的字符串个数。连续重复只以单个字符为准。",
+ "例如:aab应该返回 2, 因为它总共有 6 种排列方式: aab, aab, aba, aba, baa, baa,但是其中只有 2 个没有连续重复的字符( 字符 a 是本例中的重复字符 ):aba,aba",
+ "如果你遇到了困难,请点击 帮助 。你可以找人” 结对编程 “,但不要因此放弃思考。"
],
"solutions": [
- "function permAlone(str) {\n return permutor(str).filter(function(perm) {\n return !perm.match(/(.)\\1/g);\n }).length;\n}\n\nfunction permutor(str) {\n // http://staff.roguecc.edu/JMiller/JavaScript/permute.html\n //permArr: Global array which holds the list of permutations\n //usedChars: Global utility array which holds a list of \"currently-in-use\" characters\n var permArr = [], usedChars = [];\n function permute(input) {\n //convert input into a char array (one element for each character)\n var i, ch, chars = input.split(\"\");\n for (i = 0; i < chars.length; i++) {\n //get and remove character at index \"i\" from char array\n ch = chars.splice(i, 1);\n //add removed character to the end of used characters\n usedChars.push(ch);\n //when there are no more characters left in char array to add, add used chars to list of permutations\n if (chars.length === 0) permArr[permArr.length] = usedChars.join(\"\");\n //send characters (minus the removed one from above) from char array to be permuted\n permute(chars.join(\"\"));\n //add removed character back into char array in original position\n chars.splice(i, 0, ch);\n //remove the last character used off the end of used characters array\n usedChars.pop();\n }\n }\n permute(str);\n return permArr;\n}\n\npermAlone('aab');\n"
+ "function permAlone(str) {\n return permutor(str).filter(function(perm) {\n return !perm.match(/(.)\\1/g);\n }).length;\n}\n\nfunction permutor(str) {\n // http://staff.roguecc.edu/JMiller/JavaScript/permute.html\n //permArr: 全局数组:包含排列的列表 \ n //usedChars: 全局实用数组,其中一个列表包含 \"currently-in-use\"字符 var permArr = [], usedChars = [];\n function permute(input) {\n // 将输入参数转换成一个字符串数组 (每个字符都有一个元素)\n var i, ch, chars = input.split(\"\");\n for (i = 0; i < chars.length; i++) {\n // 从字符数组中获取并删除索引为\"i\"的字符 \n ch = chars.splice(i, 1);\n // 将删除的字符增加的使用字符的末尾 \n usedChars.push(ch);\n // 当char数组中没有其他字符添加时,添加使用的chars列表来排列排列 \n if (chars.length === 0) permArr[permArr.length] = usedChars.join(\"\");\n // 从char数组发送字符(减去上面删除的字符)进行置换 \n permute(chars.join(\"\"));\n // 将删除的数组添加回char数组中的原位置 \n chars.splice(i, 0, ch);\n //删除使用过的字符数组末尾使用的最后一个字符 \n usedChars.pop();\n }\n }\n permute(str);\n return permArr;\n}\n\npermAlone('aab');\n"
],
"tests": [
{
- "text": "permAlone(\"aab\") should return a number.",
- "testString": "assert.isNumber(permAlone('aab'), 'permAlone(\"aab\") should return a number.');"
+ "text": "permAlone(\"aab\")应该返回一个数字。",
+ "testString": "assert.isNumber(permAlone('aab'),'permAlone(\"aab\")应该返回一个数字。');"
},
{
- "text": "permAlone(\"aab\") should return 2.",
- "testString": "assert.strictEqual(permAlone('aab'), 2, 'permAlone(\"aab\") should return 2.');"
+ "text": "permAlone(\"aab\")应该返回 2。",
+ "testString": "assert.strictEqual(permAlone('aab'), 2,'permAlone(\"aab\")应该返回 2。');"
},
{
- "text": "permAlone(\"aaa\") should return 0.",
- "testString": "assert.strictEqual(permAlone('aaa'), 0, 'permAlone(\"aaa\") should return 0.');"
+ "text": "permAlone(\"aaa\")应该返回 0。",
+ "testString": "assert.strictEqual(permAlone('aaa'), 0,'permAlone(\"aaa\")应该返回 0。');"
},
{
- "text": "permAlone(\"aabb\") should return 8.",
- "testString": "assert.strictEqual(permAlone('aabb'), 8, 'permAlone(\"aabb\") should return 8.');"
+ "text": "permAlone(\"aabb\")应该返回 8。",
+ "testString": "assert.strictEqual(permAlone('aabb'), 8,'permAlone(\"aabb\")应该返回 8。');"
},
{
- "text": "permAlone(\"abcdefa\") should return 3600.",
- "testString": "assert.strictEqual(permAlone('abcdefa'), 3600, 'permAlone(\"abcdefa\") should return 3600.');"
+ "text": "permAlone(\"abcdefa\")应该返回 3600。",
+ "testString": "assert.strictEqual(permAlone('abcdefa'), 3600,'permAlone(\"abcdefa\") 应该返回 3600。');"
},
{
- "text": "permAlone(\"abfdefa\") should return 2640.",
- "testString": "assert.strictEqual(permAlone('abfdefa'), 2640, 'permAlone(\"abfdefa\") should return 2640.');"
+ "text": "permAlone(\"abfdefa\")应该返回 2640。",
+ "testString": "assert.strictEqual(permAlone('abfdefa'), 2640,'permAlone(\"abfdefa\")应该返回 2640。');"
},
{
- "text": "permAlone(\"zzzzzzzz\") should return 0.",
- "testString": "assert.strictEqual(permAlone('zzzzzzzz'), 0, 'permAlone(\"zzzzzzzz\") should return 0.');"
+ "text": "permAlone(\"zzzzzzzz\")应该返回 0。",
+ "testString": "assert.strictEqual(permAlone('zzzzzzzz'), 0,'permAlone(\"zzzzzzzz\")应该返回 0。');"
},
{
- "text": "permAlone(\"a\") should return 1.",
- "testString": "assert.strictEqual(permAlone('a'), 1, 'permAlone(\"a\") should return 1.');"
+ "text": "permAlone(\"a\")应该返回 1。",
+ "testString": "assert.strictEqual(permAlone('a'), 1,'permAlone(\"a\")应该返回 1。');"
},
{
- "text": "permAlone(\"aaab\") should return 0.",
- "testString": "assert.strictEqual(permAlone('aaab'), 0, 'permAlone(\"aaab\") should return 0.');"
+ "text": "permAlone(\"aaab\")应该返回 0。",
+ "testString": "assert.strictEqual(permAlone('aaab'), 0,'permAlone(\"aaab\")应该返回 0。');"
},
{
- "text": "permAlone(\"aaabb\") should return 12.",
- "testString": "assert.strictEqual(permAlone('aaabb'), 12, 'permAlone(\"aaabb\") should return 12.');"
+ "text": "permAlone(\"aaabb\")应该返回 12。",
+ "testString": "assert.strictEqual(permAlone('aaabb'), 12,'permAlone(\"aaabb\")应该返回 12。');"
}
],
"MDNlinks": [
@@ -584,4 +585,4 @@
}
}
]
-}
\ No newline at end of file
+}