From 5c65a934e9665e091d52a02a53038a2a2ad245bb Mon Sep 17 00:00:00 2001 From: MoverLee Date: Wed, 18 Jul 2018 23:04:32 +0800 Subject: [PATCH 01/17] Init --- .DS_Store | Bin 0 -> 8196 bytes 08-coding-interview-prep/algorithms.json | 3 ++- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..266076d47015893c518dda68e8a41e9ef3ccc346 GIT binary patch literal 8196 zcmeHM-A)rh6g~r}Ta3Vk3f}FFi5D#?KWd3FsTD4`FfrEXg&Npx7Z|eLt=%mR)SBM- z4)_SZiErS8_yGEynW3}`#7IIgGLy`l`8(g4`OeI4&z6WprCnbjnj<0yndQt)6sIH} z=X@fKnVu;~0ezx?5^7RR5u{C)0n318z%pPNunhc*4B(y3$vNY_uSacZ8L$joNe1}& z;3Bgu8`;-VJvvaR5CC!l-72AuI6&#RMwX52YpGO$siOyBRD}sKgjUD6%hMstM)tMT z>Lj!}31eB92t_FC&~w#v5@juIX&JB#oMeDw_c&c@8`=W&#JG74HsS=IwgdH+^M^|(`s+fhAH zI8{C1I5{V`F*DokE|yApce&WhyWPhti+Q)SRO8*B~x?=I{vL30bU`CATK3k+@u`#$O&j`nRZJ^D}#OMtm*+T7 z7J&E&I1+o?QcO0ESA%{=t0~STIM^Su_;IlQqy9wgiFt|G_UK;J4LQu*kP`4}uv%C4 zx6L}z!43l4yaM*h9&2Xs*ki+Z)7Z(1!sGp?K-^Ls@EJJWM}MLHpWe`(#TYc0gg3s$Pt5Y};67!lk=lmSqMVoKaJl8V1d@_f1(X`1jaKQ|WYy3Hm z|JTm`{(r%%u<(`v%fMwaASPC;s}-!^=*Mh!F&t~V$eYNVcwS#irGi3*z>% literal 0 HcmV?d00001 diff --git a/08-coding-interview-prep/algorithms.json b/08-coding-interview-prep/algorithms.json index 7f1dcb8..65fa866 100644 --- a/08-coding-interview-prep/algorithms.json +++ b/08-coding-interview-prep/algorithms.json @@ -8,6 +8,7 @@ "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." @@ -584,4 +585,4 @@ } } ] -} \ No newline at end of file +} From ef29b827f24d136d50cbbc793f1a16ad4a2d55f4 Mon Sep 17 00:00:00 2001 From: MoverLee Date: Sun, 22 Jul 2018 11:39:21 +0800 Subject: [PATCH 02/17] Finished the Symmetric Difference --- 08-coding-interview-prep/algorithms.json | 64 ++++++++++++------------ 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/08-coding-interview-prep/algorithms.json b/08-coding-interview-prep/algorithms.json index 65fa866..83fb8fb 100644 --- a/08-coding-interview-prep/algorithms.json +++ b/08-coding-interview-prep/algorithms.json @@ -8,70 +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),数学上,两个 集合 的对称差是只属于其中一个集合,而不属于另一个集合的元素组成的集合,例如:集合 A = { 1, 2, 3} 和 B = { 2, 3, 4} 的对称差为 A △ B = C = {1,4},。 集合论中的这个运算相当于布尔逻辑中的异或运算。百科。", + "创建一个函数sym,输入两个或两个以上的数组作为参数,然后返回值为 **对称差** 的数组", + "思路:设定两个数组 (例如:A = {1, 2, 3}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]) 的返回值应该是[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": [ From 53201c0ad7b5a25240873dc783b8c681ae26e7c0 Mon Sep 17 00:00:00 2001 From: MoverLee Date: Sun, 22 Jul 2018 11:43:59 +0800 Subject: [PATCH 03/17] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=BA=E7=A7=B0?= =?UTF-8?q?=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 08-coding-interview-prep/algorithms.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/08-coding-interview-prep/algorithms.json b/08-coding-interview-prep/algorithms.json index 83fb8fb..ed4593f 100644 --- a/08-coding-interview-prep/algorithms.json +++ b/08-coding-interview-prep/algorithms.json @@ -11,7 +11,7 @@ "知识提要:对称差 (Symmetric Difference),数学上,两个 集合 的对称差是只属于其中一个集合,而不属于另一个集合的元素组成的集合,例如:集合 A = { 1, 2, 3} 和 B = { 2, 3, 4} 的对称差为 A △ B = C = {1,4},。 集合论中的这个运算相当于布尔逻辑中的异或运算。百科。", "创建一个函数sym,输入两个或两个以上的数组作为参数,然后返回值为 **对称差** 的数组", "思路:设定两个数组 (例如:A = {1, 2, 3}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" From cc924eaeed3be19ff483f39ac7d442c9bdb41bb2 Mon Sep 17 00:00:00 2001 From: MoverLee Date: Sun, 22 Jul 2018 13:31:07 +0800 Subject: [PATCH 04/17] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 08-coding-interview-prep/algorithms.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/08-coding-interview-prep/algorithms.json b/08-coding-interview-prep/algorithms.json index ed4593f..decee34 100644 --- a/08-coding-interview-prep/algorithms.json +++ b/08-coding-interview-prep/algorithms.json @@ -11,7 +11,7 @@ "知识提要:对称差 (Symmetric Difference),数学上,两个 集合 的对称差是只属于其中一个集合,而不属于另一个集合的元素组成的集合,例如:集合 A = { 1, 2, 3} 和 B = { 2, 3, 4} 的对称差为 A △ B = C = {1,4},。 集合论中的这个运算相当于布尔逻辑中的异或运算。百科。", "创建一个函数sym,输入两个或两个以上的数组作为参数,然后返回值为 **对称差** 的数组", "思路:设定两个数组 (例如:A = {1, 2, 3}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" @@ -101,7 +101,7 @@ "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." + "如果你遇到了困难,请点击 帮助。请尽量编写属于你自己的代码。尝试一下 **结对编程** 会有意料不到的惊喜哦。", ], "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" From ddb98749e54b3217a8422dd3b2bdaf5743d7af9a Mon Sep 17 00:00:00 2001 From: MoverLee Date: Sun, 22 Jul 2018 16:50:53 +0800 Subject: [PATCH 05/17] Finished Inventory Update --- 08-coding-interview-prep/algorithms.json | 27 ++++++++++++------------ 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/08-coding-interview-prep/algorithms.json b/08-coding-interview-prep/algorithms.json index decee34..ca232b7 100644 --- a/08-coding-interview-prep/algorithms.json +++ b/08-coding-interview-prep/algorithms.json @@ -100,7 +100,8 @@ "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.", + "", + "比较和更新存储在 2D数组 中的库存,并将其与新交付的第二个2D数组进行比较。更新当前的库存项数量(arr1)。如果找不到项目,请将新项目和数量添加到库存数组中。返回的库存数组应该按照项目的字母顺序排列。", "如果你遇到了困难,请点击 帮助。请尽量编写属于你自己的代码。尝试一下 **结对编程** 会有意料不到的惊喜哦。", ], "solutions": [ @@ -108,28 +109,28 @@ ], "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": [ From 6228f6ec696be3cf7dd82e7bb35e440900048412 Mon Sep 17 00:00:00 2001 From: MoverLee Date: Sun, 22 Jul 2018 18:19:06 +0800 Subject: [PATCH 06/17] test --- 08-coding-interview-prep/algorithms.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/08-coding-interview-prep/algorithms.json b/08-coding-interview-prep/algorithms.json index ca232b7..30a9b8e 100644 --- a/08-coding-interview-prep/algorithms.json +++ b/08-coding-interview-prep/algorithms.json @@ -174,9 +174,10 @@ "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." + "如果你遇到了困难,请点击 帮助。请尽量编写属于你自己的代码。尝试一下 **结对编程** 会有意料不到的惊喜哦。" ], "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" From 7a878ebb3612432e8ebd2b2a258c357d5076f07e Mon Sep 17 00:00:00 2001 From: MoverLee Date: Sun, 22 Jul 2018 23:11:24 +0800 Subject: [PATCH 07/17] Undone --- 08-coding-interview-prep/algorithms.json | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/08-coding-interview-prep/algorithms.json b/08-coding-interview-prep/algorithms.json index 30a9b8e..b2d84c3 100644 --- a/08-coding-interview-prep/algorithms.json +++ b/08-coding-interview-prep/algorithms.json @@ -105,7 +105,7 @@ "如果你遇到了困难,请点击 帮助。请尽量编写属于你自己的代码。尝试一下 **结对编程** 会有意料不到的惊喜哦。", ], "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": [ { @@ -175,12 +175,11 @@ "title": "No Repeats Please", "description": [ "把一个字符串中的字符重新排列生成新的字符串,返回新生成的字符串里没有连续重复字符的字符串个数。连续重复只以单个字符为准。", - "例如:", - "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.", + "例如:aab 应该返回 2 , 因为它总共有 6 种排列方式: aabaababaababaabaa,但是其中只有 2 个没有连续重复的字符( 字符 a 是本例中的重复字符 ):abaaba", "如果你遇到了困难,请点击 帮助。请尽量编写属于你自己的代码。尝试一下 **结对编程** 会有意料不到的惊喜哦。" ], "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: 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" ], "tests": [ { From d8c8d1f10bc9dbe57eb3f64da3bb3b86ceded430 Mon Sep 17 00:00:00 2001 From: MoverLee Date: Mon, 23 Jul 2018 09:26:11 +0800 Subject: [PATCH 08/17] Format by pangu --- 08-coding-interview-prep/algorithms.json | 210 +++++++++++------------ 1 file changed, 105 insertions(+), 105 deletions(-) diff --git a/08-coding-interview-prep/algorithms.json b/08-coding-interview-prep/algorithms.json index b2d84c3..dd2c0f9 100644 --- a/08-coding-interview-prep/algorithms.json +++ b/08-coding-interview-prep/algorithms.json @@ -8,70 +8,70 @@ "id": "a3f503de51cf954ede28891d", "title": "Find the Symmetric Difference", "description": [ - "知识提要:对称差 (Symmetric Difference),数学上,两个 集合 的对称差是只属于其中一个集合,而不属于另一个集合的元素组成的集合,例如:集合 A = { 1, 2, 3} 和 B = { 2, 3, 4} 的对称差为 A △ B = C = {1,4},。 集合论中的这个运算相当于布尔逻辑中的异或运算。百科。", - "创建一个函数sym,输入两个或两个以上的数组作为参数,然后返回值为 **对称差** 的数组", - "思路:设定两个数组 (例如:A = {1, 2, 3}B = {2, 3, 4},)作为参数传入,返回对称差数组(A △ B = C = {1, 4}),且数组元素具有唯一性(没有重复项)。", - "如果你遇到了困难,请点击 帮助。请尽量编写属于你自己的代码。尝试一下 **结对编程** 会有意料不到的惊喜哦。", + "知识提要:对称差 (Symmetric Difference),数学上,两个 集合 的对称差是只属于其中一个集合,而不属于另一个集合的元素组成的集合,例如:集合 A = { 1, 2, 3} 和 B = { 2, 3, 4} 的对称差为 A △ B = C = {1,4},。 集合论中的这个运算相当于布尔逻辑中的异或运算。 百科 。", + "创建一个函数 sym,输入两个或两个以上的数组作为参数,然后返回值为 ** 对称差 ** 的数组", + "思路:设定两个数组 (例如:A = {1, 2, 3}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]) 的返回值应该是[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]) 的返回值应该是 < 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]) 的返回值应该是 < code>[3, 4, 5]。');" }, { "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]) 的返回值应该只包含三个元素。');" + "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]) 的返回值应该是 [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]。');" + "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]) 的返回值应该只包含三个元素。", - "testString": "assert.equal(sym([1, 2, 3, 3], [5, 2, 1, 4]).length, 3, '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]) 的返回值应该是 [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]。');" + "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]) 的返回值应该只包含三个元素。", - "testString": "assert.equal(sym([1, 2, 3], [5, 2, 1, 4, 5]).length, 3, '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]) 的返回值应该是 [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]。');" + "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]) 的返回值应该只包含三个元素。", - "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]) 的返回值应该只包含三个元素。');" + "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]) 的返回值应该是 [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]。');" + "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]) 的返回值应该只包含三个元素。", - "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]) 的返回值应该只包含三个元素。');" + "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]) 的返回值应该是 [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]。');" + "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]) 的返回值应该只包含五个元素。", - "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]) 的返回值应该只包含五个元素。');" + "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]) 的返回值应该是 [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]。');" + "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]) 的返回值应该只包含八个元素。", - "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]) 的返回值应该只包含八个元素。');" + "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": [ @@ -86,7 +86,7 @@ "name": "index", "contents": [ "function sym(args) {", - " return args;", + "return args;", "}", "", "sym([1, 2, 3], [5, 2, 1, 4]);" @@ -101,36 +101,36 @@ "title": "Inventory Update", "description": [ "", - "比较和更新存储在 2D数组 中的库存,并将其与新交付的第二个2D数组进行比较。更新当前的库存项数量(arr1)。如果找不到项目,请将新项目和数量添加到库存数组中。返回的库存数组应该按照项目的字母顺序排列。", - "如果你遇到了困难,请点击 帮助。请尽量编写属于你自己的代码。尝试一下 **结对编程** 会有意料不到的惊喜哦。", + "比较和更新存储在 二维数组 中的库存,并将其与新交付的第二个二维数组进行比较。更新当前的库存项数量(arr1)。如果找不到项目,请将新项目和数量添加到库存数组中。返回的库存数组应该按照项目的字母顺序排列。", + "如果你遇到了困难,请点击 帮助 。你可以找人 “结对编程”,但不要因此放弃思考。", ], "solutions": [ - "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" + "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": "函数 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 的返回值应该是一个数组。');" + "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\"]]) 返回的数组长度应该为 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 。');" + "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\"]]) 的返回值应该是 [[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\"]].');" + "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\"]], []) 的返回值应该是 [[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\"]].');" + "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\"]]) 的返回值应该是 [[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\"]].');" + "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\"]]) 的返回值应该是 [[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\"]].');" + "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": [ @@ -144,23 +144,23 @@ "name": "index", "contents": [ "function updateInventory(arr1, arr2) {", - " // All inventory must be accounted for or you're fired!", - " return arr1;", + "// All inventory must be accounted for or you're fired!", + "return arr1;", "}", "", "// Example inventory lists", "var curInv = [", - " [21, \"Bowling Ball\"],", - " [2, \"Dirty Sock\"],", - " [1, \"Hair Pin\"],", - " [5, \"Microphone\"]", + "[21, \"Bowling Ball\"],", + "[2, \"Dirty Sock\"],", + "[1, \"Hair Pin\"],", + "[5, \"Microphone\"]", "];", "", "var newInv = [", - " [2, \"Hair Pin\"],", - " [3, \"Half-Eaten Apple\"],", - " [67, \"Bowling Ball\"],", - " [7, \"Toothpaste\"]", + "[2, \"Hair Pin\"],", + "[3, \"Half-Eaten Apple\"],", + "[67, \"Bowling Ball\"],", + "[7, \"Toothpaste\"]", "];", "", "updateInventory(curInv, newInv);" @@ -176,51 +176,51 @@ "description": [ "把一个字符串中的字符重新排列生成新的字符串,返回新生成的字符串里没有连续重复字符的字符串个数。连续重复只以单个字符为准。", "例如:aab 应该返回 2 , 因为它总共有 6 种排列方式: aabaababaababaabaa,但是其中只有 2 个没有连续重复的字符( 字符 a 是本例中的重复字符 ):abaaba", - "如果你遇到了困难,请点击 帮助。请尽量编写属于你自己的代码。尝试一下 **结对编程** 会有意料不到的惊喜哦。" + "如果你遇到了困难,请点击 帮助 。请尽量编写属于你自己的代码。尝试一下 ** 结对编程 ** 会有意料不到的惊喜哦。" ], "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: 全局数组:包含排列的列表\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: 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" ], "tests": [ { "text": "permAlone(\"aab\") should return a number.", - "testString": "assert.isNumber(permAlone('aab'), 'permAlone(\"aab\") should return a number.');" + "testString": "assert.isNumber(permAlone('aab'),'permAlone(\"aab\") should return a number.');" }, { "text": "permAlone(\"aab\") should return 2.", - "testString": "assert.strictEqual(permAlone('aab'), 2, 'permAlone(\"aab\") should return 2.');" + "testString": "assert.strictEqual(permAlone('aab'), 2,'permAlone(\"aab\") should return 2.');" }, { "text": "permAlone(\"aaa\") should return 0.", - "testString": "assert.strictEqual(permAlone('aaa'), 0, 'permAlone(\"aaa\") should return 0.');" + "testString": "assert.strictEqual(permAlone('aaa'), 0,'permAlone(\"aaa\") should return 0.');" }, { "text": "permAlone(\"aabb\") should return 8.", - "testString": "assert.strictEqual(permAlone('aabb'), 8, 'permAlone(\"aabb\") should return 8.');" + "testString": "assert.strictEqual(permAlone('aabb'), 8,'permAlone(\"aabb\") should return 8.');" }, { "text": "permAlone(\"abcdefa\") should return 3600.", - "testString": "assert.strictEqual(permAlone('abcdefa'), 3600, 'permAlone(\"abcdefa\") should return 3600.');" + "testString": "assert.strictEqual(permAlone('abcdefa'), 3600,'permAlone(\"abcdefa\") should return 3600.');" }, { "text": "permAlone(\"abfdefa\") should return 2640.", - "testString": "assert.strictEqual(permAlone('abfdefa'), 2640, 'permAlone(\"abfdefa\") should return 2640.');" + "testString": "assert.strictEqual(permAlone('abfdefa'), 2640,'permAlone(\"abfdefa\") should return 2640.');" }, { "text": "permAlone(\"zzzzzzzz\") should return 0.", - "testString": "assert.strictEqual(permAlone('zzzzzzzz'), 0, 'permAlone(\"zzzzzzzz\") should return 0.');" + "testString": "assert.strictEqual(permAlone('zzzzzzzz'), 0,'permAlone(\"zzzzzzzz\") should return 0.');" }, { "text": "permAlone(\"a\") should return 1.", - "testString": "assert.strictEqual(permAlone('a'), 1, 'permAlone(\"a\") should return 1.');" + "testString": "assert.strictEqual(permAlone('a'), 1,'permAlone(\"a\") should return 1.');" }, { "text": "permAlone(\"aaab\") should return 0.", - "testString": "assert.strictEqual(permAlone('aaab'), 0, 'permAlone(\"aaab\") should return 0.');" + "testString": "assert.strictEqual(permAlone('aaab'), 0,'permAlone(\"aaab\") should return 0.');" }, { "text": "permAlone(\"aaabb\") should return 12.", - "testString": "assert.strictEqual(permAlone('aaabb'), 12, 'permAlone(\"aaabb\") should return 12.');" + "testString": "assert.strictEqual(permAlone('aaabb'), 12,'permAlone(\"aaabb\") should return 12.');" } ], "MDNlinks": [ @@ -235,7 +235,7 @@ "name": "index", "contents": [ "function permAlone(str) {", - " return str;", + "return str;", "}", "", "permAlone('aab');" @@ -255,7 +255,7 @@ "
Index01234
Value79111315
", "Below we'll take their corresponding indices and add them.", "7 + 13 = 20 → Indices 0 + 3 = 3
9 + 11 = 20 → Indices 1 + 2 = 3
3 + 3 = 6 → Return 6", - "Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code." + "Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code." ], "solutions": [ "function pairwise(arr, arg) {\n var sum = 0;\n arr.forEach(function(e, i, a) {\n if (e != null) { \n var diff = arg-e;\n a[i] = null;\n var dix = a.indexOf(diff);\n if (dix !== -1) {\n sum += dix;\n sum += i;\n a[dix] = null;\n } \n }\n });\n return sum;\n}\n\npairwise([1,4,2,3,0,5], 7);\n" @@ -263,23 +263,23 @@ "tests": [ { "text": "pairwise([1, 4, 2, 3, 0, 5], 7) should return 11.", - "testString": "assert.deepEqual(pairwise([1, 4, 2, 3, 0, 5], 7), 11, 'pairwise([1, 4, 2, 3, 0, 5], 7) should return 11.');" + "testString": "assert.deepEqual(pairwise([1, 4, 2, 3, 0, 5], 7), 11,'pairwise([1, 4, 2, 3, 0, 5], 7) should return 11.');" }, { "text": "pairwise([1, 3, 2, 4], 4) should return 1.", - "testString": "assert.deepEqual(pairwise([1, 3, 2, 4], 4), 1, 'pairwise([1, 3, 2, 4], 4) should return 1.');" + "testString": "assert.deepEqual(pairwise([1, 3, 2, 4], 4), 1,'pairwise([1, 3, 2, 4], 4) should return 1.');" }, { "text": "pairwise([1, 1, 1], 2) should return 1.", - "testString": "assert.deepEqual(pairwise([1, 1, 1], 2), 1, 'pairwise([1, 1, 1], 2) should return 1.');" + "testString": "assert.deepEqual(pairwise([1, 1, 1], 2), 1,'pairwise([1, 1, 1], 2) should return 1.');" }, { "text": "pairwise([0, 0, 0, 0, 1, 1], 1) should return 10.", - "testString": "assert.deepEqual(pairwise([0, 0, 0, 0, 1, 1], 1), 10, 'pairwise([0, 0, 0, 0, 1, 1], 1) should return 10.');" + "testString": "assert.deepEqual(pairwise([0, 0, 0, 0, 1, 1], 1), 10,'pairwise([0, 0, 0, 0, 1, 1], 1) should return 10.');" }, { "text": "pairwise([], 100) should return 0.", - "testString": "assert.deepEqual(pairwise([], 100), 0, 'pairwise([], 100) should return 0.');" + "testString": "assert.deepEqual(pairwise([], 100), 0,'pairwise([], 100) should return 0.');" } ], "MDNlinks": [ @@ -293,7 +293,7 @@ "name": "index", "contents": [ "function pairwise(arr, arg) {", - " return arg;", + "return arg;", "}", "", "pairwise([1,4,2,3,0,5], 7);" @@ -308,7 +308,7 @@ "title": "Implement Bubble Sort", "description": [ "This is the first of several challenges on sorting algorithms. Given an array of unsorted items, we want to be able to return a sorted array. We will see several different methods to do this and learn some tradeoffs between these different approaches. While most modern languages have built-in sorting methods for operations like this, it is still important to understand some of the common basic approaches and learn how they can be implemented.", - "Here we will see bubble sort. The bubble sort method starts at the beginning of an unsorted array and 'bubbles up' unsorted values towards the end, iterating through the array until it is completely sorted. It does this by comparing adjacent items and swapping them if they are out of order. The method continues looping through the array until no swaps occur at which point the array is sorted.", + "Here we will see bubble sort. The bubble sort method starts at the beginning of an unsorted array and'bubbles up'unsorted values towards the end, iterating through the array until it is completely sorted. It does this by comparing adjacent items and swapping them if they are out of order. The method continues looping through the array until no swaps occur at which point the array is sorted.", "This method requires multiple iterations through the array and for average and worst cases has quadratic time complexity. While simple, it is usually impractical in most situations.", "Instructions: Write a function bubbleSort which takes an array of integers as input and returns an array of these integers in sorted order from least to greatest.", "Note:
We are calling this function from behind the scenes; the test array we are using is commented out in the editor. Try logging array to see your sorting algorithm in action!" @@ -316,19 +316,19 @@ "tests": [ { "text": "bubbleSort is a function.", - "testString": "assert(typeof bubbleSort == 'function', 'bubbleSort is a function.');" + "testString": "assert(typeof bubbleSort =='function','bubbleSort is a function.');" }, { "text": "bubbleSort returns a sorted array (least to greatest).", - "testString": "assert(isSorted(bubbleSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])), 'bubbleSort returns a sorted array (least to greatest).');" + "testString": "assert(isSorted(bubbleSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])),'bubbleSort returns a sorted array (least to greatest).');" }, { "text": "bubbleSort returns an array that is unchanged except for order.", - "testString": "assert.sameMembers(bubbleSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92], 'bubbleSort returns an array that is unchanged except for order.');" + "testString": "assert.sameMembers(bubbleSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92],'bubbleSort returns an array that is unchanged except for order.');" }, { "text": "bubbleSort should not use the built-in .sort() method.", - "testString": "assert.strictEqual(code.search(/\\.sort\\(/), -1, 'bubbleSort should not use the built-in .sort() method.');" + "testString": "assert.strictEqual(code.search(/\\.sort\\(/), -1,'bubbleSort should not use the built-in .sort() method.');" } ], "solutions": [], @@ -341,10 +341,10 @@ "name": "index", "contents": [ "function bubbleSort(array) {", - " // change code below this line", + "// change code below this line", "", - " // change code above this line", - " return array;", + "// change code above this line", + "return array;", "}", "", "// test array:", @@ -353,8 +353,8 @@ "head": [], "tail": [ "function isSorted(arr) {", - " var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1);", - " return check(0);", + "var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1);", + "return check(0);", "};" ] } @@ -371,19 +371,19 @@ "tests": [ { "text": "selectionSort is a function.", - "testString": "assert(typeof selectionSort == 'function', 'selectionSort is a function.');" + "testString": "assert(typeof selectionSort =='function','selectionSort is a function.');" }, { "text": "selectionSort returns a sorted array (least to greatest).", - "testString": "assert(isSorted(selectionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])), 'selectionSort returns a sorted array (least to greatest).');" + "testString": "assert(isSorted(selectionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])),'selectionSort returns a sorted array (least to greatest).');" }, { "text": "selectionSort returns an array that is unchanged except for order.", - "testString": "assert.sameMembers(selectionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92], 'selectionSort returns an array that is unchanged except for order.');" + "testString": "assert.sameMembers(selectionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92],'selectionSort returns an array that is unchanged except for order.');" }, { "text": "selectionSort should not use the built-in .sort() method.", - "testString": "assert.strictEqual(code.search(/\\.sort\\(/), -1, 'selectionSort should not use the built-in .sort() method.');" + "testString": "assert.strictEqual(code.search(/\\.sort\\(/), -1,'selectionSort should not use the built-in .sort() method.');" } ], "solutions": [], @@ -396,10 +396,10 @@ "name": "index", "contents": [ "function selectionSort(array) {", - " // change code below this line", + "// change code below this line", "", - " // change code above this line", - " return array;", + "// change code above this line", + "return array;", "}", "", "// test array:", @@ -408,8 +408,8 @@ "head": [], "tail": [ "function isSorted(arr) {", - " var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1);", - " return check(0);", + "var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1);", + "return check(0);", "};" ] } @@ -426,19 +426,19 @@ "tests": [ { "text": "insertionSort is a function.", - "testString": "assert(typeof insertionSort == 'function', 'insertionSort is a function.');" + "testString": "assert(typeof insertionSort =='function','insertionSort is a function.');" }, { "text": "insertionSort returns a sorted array (least to greatest).", - "testString": "assert(isSorted(insertionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])), 'insertionSort returns a sorted array (least to greatest).');" + "testString": "assert(isSorted(insertionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])),'insertionSort returns a sorted array (least to greatest).');" }, { "text": "insertionSort returns an array that is unchanged except for order.", - "testString": "assert.sameMembers(insertionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92], 'insertionSort returns an array that is unchanged except for order.');" + "testString": "assert.sameMembers(insertionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92],'insertionSort returns an array that is unchanged except for order.');" }, { "text": "insertionSort should not use the built-in .sort() method.", - "testString": "assert.strictEqual(code.search(/\\.sort\\(/), -1, 'insertionSort should not use the built-in .sort() method.');" + "testString": "assert.strictEqual(code.search(/\\.sort\\(/), -1,'insertionSort should not use the built-in .sort() method.');" } ], "solutions": [], @@ -451,10 +451,10 @@ "name": "index", "contents": [ "function insertionSort(array) {", - " // change code below this line", + "// change code below this line", "", - " // change code above this line", - " return array;", + "// change code above this line", + "return array;", "}", "", "// test array:", @@ -463,8 +463,8 @@ "head": [], "tail": [ "function isSorted(arr) {", - " var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1);", - " return check(0);", + "var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1);", + "return check(0);", "};" ] } @@ -482,19 +482,19 @@ "tests": [ { "text": "quickSort is a function.", - "testString": "assert(typeof quickSort == 'function', 'quickSort is a function.');" + "testString": "assert(typeof quickSort =='function','quickSort is a function.');" }, { "text": "quickSort returns a sorted array (least to greatest).", - "testString": "assert(isSorted(quickSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])), 'quickSort returns a sorted array (least to greatest).');" + "testString": "assert(isSorted(quickSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])),'quickSort returns a sorted array (least to greatest).');" }, { "text": "quickSort returns an array that is unchanged except for order.", - "testString": "assert.sameMembers(quickSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92], 'quickSort returns an array that is unchanged except for order.');" + "testString": "assert.sameMembers(quickSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92],'quickSort returns an array that is unchanged except for order.');" }, { "text": "quickSort should not use the built-in .sort() method.", - "testString": "assert.strictEqual(code.search(/\\.sort\\(/), -1, 'quickSort should not use the built-in .sort() method.');" + "testString": "assert.strictEqual(code.search(/\\.sort\\(/), -1,'quickSort should not use the built-in .sort() method.');" } ], "solutions": [], @@ -507,10 +507,10 @@ "name": "index", "contents": [ "function quickSort(array) {", - " // change code below this line", + "// change code below this line", "", - " // change code above this line", - " return array;", + "// change code above this line", + "return array;", "}", "", "// test array:", @@ -519,8 +519,8 @@ "head": [], "tail": [ "function isSorted(arr) {", - " var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1);", - " return check(0);", + "var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1);", + "return check(0);", "};" ] } @@ -541,19 +541,19 @@ "tests": [ { "text": "mergeSort is a function.", - "testString": "assert(typeof mergeSort == 'function', 'mergeSort is a function.');" + "testString": "assert(typeof mergeSort =='function','mergeSort is a function.');" }, { "text": "mergeSort returns a sorted array (least to greatest).", - "testString": "assert(isSorted(mergeSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])), 'mergeSort returns a sorted array (least to greatest).');" + "testString": "assert(isSorted(mergeSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])),'mergeSort returns a sorted array (least to greatest).');" }, { "text": "mergeSort returns an array that is unchanged except for order.", - "testString": "assert.sameMembers(mergeSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92], 'mergeSort returns an array that is unchanged except for order.');" + "testString": "assert.sameMembers(mergeSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92],'mergeSort returns an array that is unchanged except for order.');" }, { "text": "mergeSort should not use the built-in .sort() method.", - "testString": "assert.strictEqual(code.search(/\\.sort\\(/), -1, 'mergeSort should not use the built-in .sort() method.');" + "testString": "assert.strictEqual(code.search(/\\.sort\\(/), -1,'mergeSort should not use the built-in .sort() method.');" } ], "solutions": [], @@ -566,10 +566,10 @@ "name": "index", "contents": [ "function mergeSort(array) {", - " // change code below this line", + "// change code below this line", "", - " // change code above this line", - " return array;", + "// change code above this line", + "return array;", "}", "", "// test array:", @@ -578,8 +578,8 @@ "head": [], "tail": [ "function isSorted(arr) {", - " var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1);", - " return check(0);", + "var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1);", + "return check(0);", "};" ] } From 08448f4d7763e6e18788f3924ca8a8bfd46d0c74 Mon Sep 17 00:00:00 2001 From: MoverLee Date: Tue, 24 Jul 2018 10:48:41 +0800 Subject: [PATCH 09/17] =?UTF-8?q?=E4=B8=8E=E5=85=B6=E4=BB=96=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E7=9A=84=E7=9B=B8=E5=90=8C=E4=BF=A1=E6=81=AF=E4=BF=9D?= =?UTF-8?q?=E6=8C=81=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 08-coding-interview-prep/algorithms.json | 74 ++++++++++++------------ 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/08-coding-interview-prep/algorithms.json b/08-coding-interview-prep/algorithms.json index dd2c0f9..edee9f4 100644 --- a/08-coding-interview-prep/algorithms.json +++ b/08-coding-interview-prep/algorithms.json @@ -18,60 +18,60 @@ ], "tests": [ { - "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]) 的返回值应该是 < code>[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]) 应该返回 < code>[3, 4, 5]。');" }, { "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]) 的返回值应该是 [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]) 应该返回 [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]) 的返回值应该只包含三个元素。", - "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, 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]) 的返回值应该是 [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]) 应该返回 [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]) 的返回值应该只包含三个元素。", - "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, 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]) 的返回值应该是 [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]) 应该返回 [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]) 的返回值应该只包含三个元素。", - "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, 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]) 的返回值应该是 [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]) 应该返回 [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]) 的返回值应该只包含三个元素。", - "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([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]) 的返回值应该是 [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]) 应该返回 [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]) 的返回值应该只包含五个元素。", - "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]) 返回的数组应该只包含五个元素;", + "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]) 的返回值应该是 [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]) 应该返回 [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]) 的返回值应该只包含八个元素。", - "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]) 的返回值应该只包含八个元素。');" + "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": [ @@ -109,28 +109,28 @@ ], "tests": [ { - "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 应该返回一个数组。", + "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\"]]) 返回的数组长度应该为 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 。');" + "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\"]]) 的返回值应该是 [[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\"]], [[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\"]], []) 的返回值应该是 [[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([[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\"]]) 的返回值应该是 [[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([], [[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\"]]) 的返回值应该是 [[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\"]].');" + "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": [ From 96a9f21f4093604827e1ce1c49400fb9d1b926f8 Mon Sep 17 00:00:00 2001 From: Big Face Master Date: Tue, 24 Jul 2018 23:19:15 +0800 Subject: [PATCH 10/17] No Repeats Please --- 08-coding-interview-prep/algorithms.json | 42 ++++++++++++------------ 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/08-coding-interview-prep/algorithms.json b/08-coding-interview-prep/algorithms.json index edee9f4..abdca68 100644 --- a/08-coding-interview-prep/algorithms.json +++ b/08-coding-interview-prep/algorithms.json @@ -183,44 +183,44 @@ ], "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": [ @@ -255,7 +255,7 @@ "
Index01234
Value79111315
", "Below we'll take their corresponding indices and add them.", "7 + 13 = 20 → Indices 0 + 3 = 3
9 + 11 = 20 → Indices 1 + 2 = 3
3 + 3 = 6 → Return 6", - "Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code." + "如果你遇到了困难,请点击 帮助 。你可以找人 “结对编程”,但不要因此放弃思考。", ], "solutions": [ "function pairwise(arr, arg) {\n var sum = 0;\n arr.forEach(function(e, i, a) {\n if (e != null) { \n var diff = arg-e;\n a[i] = null;\n var dix = a.indexOf(diff);\n if (dix !== -1) {\n sum += dix;\n sum += i;\n a[dix] = null;\n } \n }\n });\n return sum;\n}\n\npairwise([1,4,2,3,0,5], 7);\n" From b1fa3379e14b9ec52342472270b681761ca49637 Mon Sep 17 00:00:00 2001 From: Big Face Master Date: Thu, 26 Jul 2018 22:52:03 +0800 Subject: [PATCH 11/17] Modified by reviwer --- .DS_Store | Bin 8196 -> 0 bytes 08-coding-interview-prep/algorithms.json | 72 +++++++++++------------ 2 files changed, 36 insertions(+), 36 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 266076d47015893c518dda68e8a41e9ef3ccc346..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8196 zcmeHM-A)rh6g~r}Ta3Vk3f}FFi5D#?KWd3FsTD4`FfrEXg&Npx7Z|eLt=%mR)SBM- z4)_SZiErS8_yGEynW3}`#7IIgGLy`l`8(g4`OeI4&z6WprCnbjnj<0yndQt)6sIH} z=X@fKnVu;~0ezx?5^7RR5u{C)0n318z%pPNunhc*4B(y3$vNY_uSacZ8L$joNe1}& z;3Bgu8`;-VJvvaR5CC!l-72AuI6&#RMwX52YpGO$siOyBRD}sKgjUD6%hMstM)tMT z>Lj!}31eB92t_FC&~w#v5@juIX&JB#oMeDw_c&c@8`=W&#JG74HsS=IwgdH+^M^|(`s+fhAH zI8{C1I5{V`F*DokE|yApce&WhyWPhti+Q)SRO8*B~x?=I{vL30bU`CATK3k+@u`#$O&j`nRZJ^D}#OMtm*+T7 z7J&E&I1+o?QcO0ESA%{=t0~STIM^Su_;IlQqy9wgiFt|G_UK;J4LQu*kP`4}uv%C4 zx6L}z!43l4yaM*h9&2Xs*ki+Z)7Z(1!sGp?K-^Ls@EJJWM}MLHpWe`(#TYc0gg3s$Pt5Y};67!lk=lmSqMVoKaJl8V1d@_f1(X`1jaKQ|WYy3Hm z|JTm`{(r%%u<(`v%fMwaASPC;s}-!^=*Mh!F&t~V$eYNVcwS#irGi3*z>% diff --git a/08-coding-interview-prep/algorithms.json b/08-coding-interview-prep/algorithms.json index abdca68..305a278 100644 --- a/08-coding-interview-prep/algorithms.json +++ b/08-coding-interview-prep/algorithms.json @@ -8,10 +8,10 @@ "id": "a3f503de51cf954ede28891d", "title": "Find the Symmetric Difference", "description": [ - "知识提要:对称差 (Symmetric Difference),数学上,两个 集合 的对称差是只属于其中一个集合,而不属于另一个集合的元素组成的集合,例如:集合 A = { 1, 2, 3} 和 B = { 2, 3, 4} 的对称差为 A △ B = C = {1,4},。 集合论中的这个运算相当于布尔逻辑中的异或运算。 百科 。", - "创建一个函数 sym,输入两个或两个以上的数组作为参数,然后返回值为 ** 对称差 ** 的数组", - "思路:设定两个数组 (例如:A = {1, 2, 3}B = {2, 3, 4},) 作为参数传入,返回对称差数组(A △ B = C = {1, 4}),且数组元素具有唯一性(没有重复项)。", - "如果你遇到了困难,请点击 帮助 。你可以找人 “结对编程”,但不要因此放弃思考。", + "知识提要: 对称差 (Symmetric Difference),数学上,两个 集合 的对称差分是只属于其中一个集合,而不属于另一个集合的元素组成的集合,例如:集合 A = { 1, 2, 3} 和 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" @@ -31,7 +31,7 @@ }, { "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]) 返回的数组应该只包含三个元素');" + "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]) 应该返回 [3, 4, 5]。", @@ -62,7 +62,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]) 返回的数组应该只包含五个元素;", + "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]) 返回的数组应该只包含五个元素。');" }, { @@ -102,7 +102,7 @@ "description": [ "", "比较和更新存储在 二维数组 中的库存,并将其与新交付的第二个二维数组进行比较。更新当前的库存项数量(arr1)。如果找不到项目,请将新项目和数量添加到库存数组中。返回的库存数组应该按照项目的字母顺序排列。", - "如果你遇到了困难,请点击 帮助 。你可以找人 “结对编程”,但不要因此放弃思考。", + "如果你遇到了困难,请点击 帮助 。你可以找人” 结对编程 “,但不要因此放弃思考。", ], "solutions": [ "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" @@ -113,24 +113,24 @@ "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\"]]) 返回的数组长度应该为 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\"]]) 返回的数组长度应该为 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\"]]) 应该返回 [[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\"]].');" + "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\"]], []) 应该返回 [[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\"]].');" + "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\"]]) 应该返回 [[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\"]].');" + "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\"]]) 应该返回 [[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\"]].');" + "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": [ @@ -144,11 +144,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\"],", @@ -175,11 +175,11 @@ "title": "No Repeats Please", "description": [ "把一个字符串中的字符重新排列生成新的字符串,返回新生成的字符串里没有连续重复字符的字符串个数。连续重复只以单个字符为准。", - "例如:aab 应该返回 2 , 因为它总共有 6 种排列方式: aabaababaababaabaa,但是其中只有 2 个没有连续重复的字符( 字符 a 是本例中的重复字符 ):abaaba", - "如果你遇到了困难,请点击 帮助 。请尽量编写属于你自己的代码。尝试一下 ** 结对编程 ** 会有意料不到的惊喜哦。" + "例如:aab 应该返回 2, 因为它总共有 6 种排列方式: aabaababaababaabaa,但是其中只有 2 个没有连续重复的字符( 字符 a 是本例中的重复字符 ):abaaba", + "如果你遇到了困难,请点击 帮助 。你可以找人” 结对编程 “,但不要因此放弃思考。" ], "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: 全局数组:包含排列的列表 \ 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: 包含 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" ], "tests": [ { @@ -187,40 +187,40 @@ "testString": "assert.isNumber(permAlone('aab'),'permAlone(\"aab\") 应该返回一个数字。');" }, { - "text": "permAlone(\"aab\") 应该返回 2 。", - "testString": "assert.strictEqual(permAlone('aab'), 2,'permAlone(\"aab\") 应该返回 2 。');" + "text": "permAlone(\"aab\") 应该返回 2。", + "testString": "assert.strictEqual(permAlone('aab'), 2,'permAlone(\"aab\") 应该返回 2。');" }, { - "text": "permAlone(\"aaa\") 应该返回 0 。", - "testString": "assert.strictEqual(permAlone('aaa'), 0,'permAlone(\"aaa\") 应该返回 0 。');" + "text": "permAlone(\"aaa\") 应该返回 0。", + "testString": "assert.strictEqual(permAlone('aaa'), 0,'permAlone(\"aaa\") 应该返回 0。');" }, { - "text": "permAlone(\"aabb\") 应该返回 8 。", - "testString": "assert.strictEqual(permAlone('aabb'), 8,'permAlone(\"aabb\") 应该返回 8 。');" + "text": "permAlone(\"aabb\") 应该返回 8。", + "testString": "assert.strictEqual(permAlone('aabb'), 8,'permAlone(\"aabb\") 应该返回 8。');" }, { - "text": "permAlone(\"abcdefa\") 应该返回 3600 。", - "testString": "assert.strictEqual(permAlone('abcdefa'), 3600,'permAlone(\"abcdefa\") 应该返回 3600 。');" + "text": "permAlone(\"abcdefa\") 应该返回 3600。", + "testString": "assert.strictEqual(permAlone('abcdefa'), 3600,'permAlone(\"abcdefa\") 应该返回 3600。');" }, { - "text": "permAlone(\"abfdefa\") 应该返回 2640 。", - "testString": "assert.strictEqual(permAlone('abfdefa'), 2640,'permAlone(\"abfdefa\") 应该返回 2640 。');" + "text": "permAlone(\"abfdefa\") 应该返回 2640。", + "testString": "assert.strictEqual(permAlone('abfdefa'), 2640,'permAlone(\"abfdefa\") 应该返回 2640。');" }, { - "text": "permAlone(\"zzzzzzzz\") 应该返回 0 。", - "testString": "assert.strictEqual(permAlone('zzzzzzzz'), 0,'permAlone(\"zzzzzzzz\") 应该返回 0 。');" + "text": "permAlone(\"zzzzzzzz\") 应该返回 0。", + "testString": "assert.strictEqual(permAlone('zzzzzzzz'), 0,'permAlone(\"zzzzzzzz\") 应该返回 0。');" }, { - "text": "permAlone(\"a\") 应该返回 1 。", - "testString": "assert.strictEqual(permAlone('a'), 1,'permAlone(\"a\") 应该返回 1 。');" + "text": "permAlone(\"a\") 应该返回 1。", + "testString": "assert.strictEqual(permAlone('a'), 1,'permAlone(\"a\") 应该返回 1。');" }, { - "text": "permAlone(\"aaab\") 应该返回 0 。", - "testString": "assert.strictEqual(permAlone('aaab'), 0,'permAlone(\"aaab\") 应该返回 0 。');" + "text": "permAlone(\"aaab\") 应该返回 0。", + "testString": "assert.strictEqual(permAlone('aaab'), 0,'permAlone(\"aaab\") 应该返回 0。');" }, { - "text": "permAlone(\"aaabb\") 应该返回 12 。", - "testString": "assert.strictEqual(permAlone('aaabb'), 12,'permAlone(\"aaabb\") 应该返回 12 。');" + "text": "permAlone(\"aaabb\") 应该返回 12。", + "testString": "assert.strictEqual(permAlone('aaabb'), 12,'permAlone(\"aaabb\") 应该返回 12。');" } ], "MDNlinks": [ From 575325b9b4d7801dbb5041efeaa158b8f504ff63 Mon Sep 17 00:00:00 2001 From: Big Face Master Date: Sat, 28 Jul 2018 19:21:50 +0800 Subject: [PATCH 12/17] modified the space of chinese && code --- 08-coding-interview-prep/algorithms.json | 118 +++++++++++------------ 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/08-coding-interview-prep/algorithms.json b/08-coding-interview-prep/algorithms.json index 305a278..3afa5b8 100644 --- a/08-coding-interview-prep/algorithms.json +++ b/08-coding-interview-prep/algorithms.json @@ -18,60 +18,60 @@ ], "tests": [ { - "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]) 应该返回 < code>[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])应该返回< code>[3, 4, 5]。');" }, { - "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], [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]) 应该返回 [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])应该返回[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]) 返回的数组应该只包含三个元素", - "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, 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]) 应该返回 [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])应该返回[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]) 返回的数组应该只包含三个元素。", - "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, 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]) 应该返回 [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])应该返回[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]) 返回的数组应该只包含三个元素。", - "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, 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]) 应该返回 [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])应该返回[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]) 返回的数组应该只包含三个元素。", - "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([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]) 应该返回 [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]) 返回的数组应该只包含五个元素。", - "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])返回的数组应该只包含五个元素。", + "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]) 应该返回 [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])应该返回[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]) 返回的数组应该只包含八个元素。", - "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]) 返回的数组应该只包含八个元素。');" + "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": [ @@ -109,27 +109,27 @@ ], "tests": [ { - "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应该返回一个数组。", + "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\"]]) 返回的数组长度应该为 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\"]])返回的数组长度应该为 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\"]]) 应该返回 [[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\"]], [[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\"]], []) 应该返回 [[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([[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\"]]) 应该返回 [[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([], [[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\"]]) 应该返回 [[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\"]]。');" } ], @@ -175,52 +175,52 @@ "title": "No Repeats Please", "description": [ "把一个字符串中的字符重新排列生成新的字符串,返回新生成的字符串里没有连续重复字符的字符串个数。连续重复只以单个字符为准。", - "例如:aab 应该返回 2, 因为它总共有 6 种排列方式: aabaababaababaabaa,但是其中只有 2 个没有连续重复的字符( 字符 a 是本例中的重复字符 ):abaaba", + "例如:aab应该返回 2, 因为它总共有 6 种排列方式: aabaababaababaabaa,但是其中只有 2 个没有连续重复的字符( 字符 a 是本例中的重复字符 ):abaaba", "如果你遇到了困难,请点击 帮助 。你可以找人” 结对编程 “,但不要因此放弃思考。" ], "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: 全局数组:包含排列的列表 \ 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\") 应该返回一个数字。", - "testString": "assert.isNumber(permAlone('aab'),'permAlone(\"aab\") 应该返回一个数字。');" + "text": "permAlone(\"aab\")应该返回一个数字。", + "testString": "assert.isNumber(permAlone('aab'),'permAlone(\"aab\")应该返回一个数字。');" }, { - "text": "permAlone(\"aab\") 应该返回 2。", - "testString": "assert.strictEqual(permAlone('aab'), 2,'permAlone(\"aab\") 应该返回 2。');" + "text": "permAlone(\"aab\")应该返回 2。", + "testString": "assert.strictEqual(permAlone('aab'), 2,'permAlone(\"aab\")应该返回 2。');" }, { - "text": "permAlone(\"aaa\") 应该返回 0。", - "testString": "assert.strictEqual(permAlone('aaa'), 0,'permAlone(\"aaa\") 应该返回 0。');" + "text": "permAlone(\"aaa\")应该返回 0。", + "testString": "assert.strictEqual(permAlone('aaa'), 0,'permAlone(\"aaa\")应该返回 0。');" }, { - "text": "permAlone(\"aabb\") 应该返回 8。", - "testString": "assert.strictEqual(permAlone('aabb'), 8,'permAlone(\"aabb\") 应该返回 8。');" + "text": "permAlone(\"aabb\")应该返回 8。", + "testString": "assert.strictEqual(permAlone('aabb'), 8,'permAlone(\"aabb\")应该返回 8。');" }, { - "text": "permAlone(\"abcdefa\") 应该返回 3600。", + "text": "permAlone(\"abcdefa\")应该返回 3600。", "testString": "assert.strictEqual(permAlone('abcdefa'), 3600,'permAlone(\"abcdefa\") 应该返回 3600。');" }, { - "text": "permAlone(\"abfdefa\") 应该返回 2640。", - "testString": "assert.strictEqual(permAlone('abfdefa'), 2640,'permAlone(\"abfdefa\") 应该返回 2640。');" + "text": "permAlone(\"abfdefa\")应该返回 2640。", + "testString": "assert.strictEqual(permAlone('abfdefa'), 2640,'permAlone(\"abfdefa\")应该返回 2640。');" }, { - "text": "permAlone(\"zzzzzzzz\") 应该返回 0。", - "testString": "assert.strictEqual(permAlone('zzzzzzzz'), 0,'permAlone(\"zzzzzzzz\") 应该返回 0。');" + "text": "permAlone(\"zzzzzzzz\")应该返回 0。", + "testString": "assert.strictEqual(permAlone('zzzzzzzz'), 0,'permAlone(\"zzzzzzzz\")应该返回 0。');" }, { - "text": "permAlone(\"a\") 应该返回 1。", - "testString": "assert.strictEqual(permAlone('a'), 1,'permAlone(\"a\") 应该返回 1。');" + "text": "permAlone(\"a\")应该返回 1。", + "testString": "assert.strictEqual(permAlone('a'), 1,'permAlone(\"a\")应该返回 1。');" }, { - "text": "permAlone(\"aaab\") 应该返回 0。", - "testString": "assert.strictEqual(permAlone('aaab'), 0,'permAlone(\"aaab\") 应该返回 0。');" + "text": "permAlone(\"aaab\")应该返回 0。", + "testString": "assert.strictEqual(permAlone('aaab'), 0,'permAlone(\"aaab\")应该返回 0。');" }, { - "text": "permAlone(\"aaabb\") 应该返回 12。", - "testString": "assert.strictEqual(permAlone('aaabb'), 12,'permAlone(\"aaabb\") 应该返回 12。');" + "text": "permAlone(\"aaabb\")应该返回 12。", + "testString": "assert.strictEqual(permAlone('aaabb'), 12,'permAlone(\"aaabb\")应该返回 12。');" } ], "MDNlinks": [ From b686c287dda47fc1e5068a69fb95b18e1f9476cc Mon Sep 17 00:00:00 2001 From: Big Face Master Date: Tue, 31 Jul 2018 20:46:42 +0800 Subject: [PATCH 13/17] Modified by reviwer --- 08-coding-interview-prep/algorithms.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/08-coding-interview-prep/algorithms.json b/08-coding-interview-prep/algorithms.json index 3afa5b8..83510d1 100644 --- a/08-coding-interview-prep/algorithms.json +++ b/08-coding-interview-prep/algorithms.json @@ -8,10 +8,10 @@ "id": "a3f503de51cf954ede28891d", "title": "Find the Symmetric Difference", "description": [ - "知识提要: 对称差 (Symmetric Difference),数学上,两个 集合 的对称差分是只属于其中一个集合,而不属于另一个集合的元素组成的集合,例如:集合 A = { 1, 2, 3} 和 B = { 2, 3, 4} 的对称差分为 A △ B = C = {1,4},。 集合论中的这个运算相当于布尔逻辑中的异或运算。", - "创建一个函数 sym,输入两个或两个以上的数组作为参数,然后返回值为 ** 对称差分 ** 的数组", + "知识提要: 对称差 (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" @@ -101,8 +101,8 @@ "title": "Inventory Update", "description": [ "", - "比较和更新存储在 二维数组 中的库存,并将其与新交付的第二个二维数组进行比较。更新当前的库存项数量(arr1)。如果找不到项目,请将新项目和数量添加到库存数组中。返回的库存数组应该按照项目的字母顺序排列。", - "如果你遇到了困难,请点击 帮助 。你可以找人” 结对编程 “,但不要因此放弃思考。", + "比较和更新存储在 二维数组 中的库存,并将其与新交付的第二个二维数组进行比较。更新当前的库存项数量(arr1)。如果找不到项目,请将新项目和数量添加到库存数组中。返回的库存数组应该按照项目的字母顺序排列。", + "如果你遇到了困难,请点击帮助。你可以找人“结对编程“,但不要因此放弃思考。", ], "solutions": [ "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" From d888fa98820c9e7725ca60ddf683fcf90686f888 Mon Sep 17 00:00:00 2001 From: Big Face Master Date: Tue, 31 Jul 2018 21:11:39 +0800 Subject: [PATCH 14/17] Delete the space --- 08-coding-interview-prep/algorithms.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/08-coding-interview-prep/algorithms.json b/08-coding-interview-prep/algorithms.json index 83510d1..1db401c 100644 --- a/08-coding-interview-prep/algorithms.json +++ b/08-coding-interview-prep/algorithms.json @@ -8,9 +8,9 @@ "id": "a3f503de51cf954ede28891d", "title": "Find the Symmetric Difference", "description": [ - "知识提要: 对称差 (Symmetric Difference),数学上,两个 集合 的对称差分是只属于其中一个集合,而不属于另一个集合的元素组成的集合,例如:集合let A = [ 1, 2, 3]let B = [ 2, 3, 4]的对称差分为A △ B = C = [ 1, 4],。 集合论中的这个运算相当于布尔逻辑中的异或运算。", + "知识提要:对称差 (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]),且数组元素具有唯一性(没有重复项)。", + "思路:设定两个数组 (例如:let A = [1, 2, 3]let B = [2, 3, 4],)作为参数传入,返回对称差分数组(A △ B = C = [1, 4]),且数组元素具有唯一性(没有重复项)。", "如果你遇到了困难,请点击 帮助。你可以找人“结对编程”,但不要因此放弃思考。", ], "solutions": [ @@ -19,7 +19,7 @@ "tests": [ { "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])应该返回< 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])的返回值应该只包含三个元素。", @@ -101,7 +101,7 @@ "title": "Inventory Update", "description": [ "", - "比较和更新存储在 二维数组 中的库存,并将其与新交付的第二个二维数组进行比较。更新当前的库存项数量(arr1)。如果找不到项目,请将新项目和数量添加到库存数组中。返回的库存数组应该按照项目的字母顺序排列。", + "比较和更新存储在二维数组中的库存,并将其与新交付的第二个二维数组进行比较。更新当前的库存项数量(arr1)。如果找不到项目,请将新项目和数量添加到库存数组中。返回的库存数组应该按照项目的字母顺序排列。", "如果你遇到了困难,请点击帮助。你可以找人“结对编程“,但不要因此放弃思考。", ], "solutions": [ From 83a8be9d32247de900e229dcc9c1ae2fc8fa004a Mon Sep 17 00:00:00 2001 From: Big Face Master Date: Sun, 5 Aug 2018 20:31:01 +0800 Subject: [PATCH 15/17] Modified by reviwer --- 08-coding-interview-prep/algorithms.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/08-coding-interview-prep/algorithms.json b/08-coding-interview-prep/algorithms.json index 1db401c..4ab2f10 100644 --- a/08-coding-interview-prep/algorithms.json +++ b/08-coding-interview-prep/algorithms.json @@ -100,8 +100,7 @@ "id": "a56138aff60341a09ed6c480", "title": "Inventory Update", "description": [ - "", - "比较和更新存储在二维数组中的库存,并将其与新交付的第二个二维数组进行比较。更新当前的库存项数量(arr1)。如果找不到项目,请将新项目和数量添加到库存数组中。返回的库存数组应该按照项目的字母顺序排列。", + "创建一个二维数组,比较并更新存储在二维数组中的”库存“元素,然后并将其与新产生的第二个二维数组进行对比,更新当前的”库存“项的数量(arr1),如果找不到这个对比对象,那么将新的对象和数量添加到“库存”数组中。注意:返回的“库存”数组应该是按照数组元素的首字母顺序排序", "如果你遇到了困难,请点击帮助。你可以找人“结对编程“,但不要因此放弃思考。", ], "solutions": [ From df7b55ebb02fed3fefad2ec8a042a7ee71d12a7c Mon Sep 17 00:00:00 2001 From: Big Face Master Date: Mon, 6 Aug 2018 14:00:35 +0800 Subject: [PATCH 16/17] Modified by reviwer --- 08-coding-interview-prep/algorithms.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/08-coding-interview-prep/algorithms.json b/08-coding-interview-prep/algorithms.json index 4ab2f10..7c20671 100644 --- a/08-coding-interview-prep/algorithms.json +++ b/08-coding-interview-prep/algorithms.json @@ -8,10 +8,10 @@ "id": "a3f503de51cf954ede28891d", "title": "Find the Symmetric Difference", "description": [ - "知识提要:对称差 (Symmetric Difference),数学上,两个 集合 的对称差分是只属于其中一个集合,而不属于另一个集合的元素组成的集合,例如:集合let A = [ 1, 2, 3]let B = [ 2, 3, 4]的对称差分为A △ B = C = [ 1, 4],。 集合论中的这个运算相当于布尔逻辑中的异或运算。", + "知识提要:对称差 (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]),且数组元素具有唯一性(没有重复项)。", - "如果你遇到了困难,请点击 帮助。你可以找人“结对编程”,但不要因此放弃思考。", + "思路:设定两个数组 (例如: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" @@ -100,8 +100,8 @@ "id": "a56138aff60341a09ed6c480", "title": "Inventory Update", "description": [ - "创建一个二维数组,比较并更新存储在二维数组中的”库存“元素,然后并将其与新产生的第二个二维数组进行对比,更新当前的”库存“项的数量(arr1),如果找不到这个对比对象,那么将新的对象和数量添加到“库存”数组中。注意:返回的“库存”数组应该是按照数组元素的首字母顺序排序", - "如果你遇到了困难,请点击帮助。你可以找人“结对编程“,但不要因此放弃思考。", + "创建一个二维数组,比较并更新存储在二维数组中的 ”库存“ 元素,然后并将其与新产生的第二个二维数组进行对比,更新当前的 ”库存“ 项的数量(arr1),如果找不到这个对比对象,那么将新的对象和数量添加到 “库存” 数组中。注意:返回的 “库存” 数组应该是按照数组元素的首字母顺序排序", + "如果你遇到了困难,请点击帮助。你可以找人“结对编程“,但不要因此放弃思考。", ], "solutions": [ "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" From d13f95544c973687c03ca70efa1d9cbca4bf6d68 Mon Sep 17 00:00:00 2001 From: Big Face Master Date: Mon, 6 Aug 2018 15:08:35 +0800 Subject: [PATCH 17/17] Recover space --- 08-coding-interview-prep/algorithms.json | 128 +++++++++++------------ 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/08-coding-interview-prep/algorithms.json b/08-coding-interview-prep/algorithms.json index 7c20671..77ccf94 100644 --- a/08-coding-interview-prep/algorithms.json +++ b/08-coding-interview-prep/algorithms.json @@ -86,7 +86,7 @@ "name": "index", "contents": [ "function sym(args) {", - "return args;", + " return args;", "}", "", "sym([1, 2, 3], [5, 2, 1, 4]);" @@ -144,22 +144,22 @@ "contents": [ "function updateInventory(arr1, arr2) {", "// 所有的存货都必须记帐,否则你将被解雇!", - "return arr1;", + " return arr1;", "}", "", "// 两个货物列表示例", "var curInv = [", - "[21, \"Bowling Ball\"],", - "[2, \"Dirty Sock\"],", - "[1, \"Hair Pin\"],", - "[5, \"Microphone\"]", + " [21, \"Bowling Ball\"],", + " [2, \"Dirty Sock\"],", + " [1, \"Hair Pin\"],", + " [5, \"Microphone\"]", "];", "", "var newInv = [", - "[2, \"Hair Pin\"],", - "[3, \"Half-Eaten Apple\"],", - "[67, \"Bowling Ball\"],", - "[7, \"Toothpaste\"]", + " [2, \"Hair Pin\"],", + " [3, \"Half-Eaten Apple\"],", + " [67, \"Bowling Ball\"],", + " [7, \"Toothpaste\"]", "];", "", "updateInventory(curInv, newInv);" @@ -234,7 +234,7 @@ "name": "index", "contents": [ "function permAlone(str) {", - "return str;", + " return str;", "}", "", "permAlone('aab');" @@ -254,7 +254,7 @@ "
Index01234
Value79111315
", "Below we'll take their corresponding indices and add them.", "7 + 13 = 20 → Indices 0 + 3 = 3
9 + 11 = 20 → Indices 1 + 2 = 3
3 + 3 = 6 → Return 6", - "如果你遇到了困难,请点击 帮助 。你可以找人 “结对编程”,但不要因此放弃思考。", + "Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code." ], "solutions": [ "function pairwise(arr, arg) {\n var sum = 0;\n arr.forEach(function(e, i, a) {\n if (e != null) { \n var diff = arg-e;\n a[i] = null;\n var dix = a.indexOf(diff);\n if (dix !== -1) {\n sum += dix;\n sum += i;\n a[dix] = null;\n } \n }\n });\n return sum;\n}\n\npairwise([1,4,2,3,0,5], 7);\n" @@ -262,23 +262,23 @@ "tests": [ { "text": "pairwise([1, 4, 2, 3, 0, 5], 7) should return 11.", - "testString": "assert.deepEqual(pairwise([1, 4, 2, 3, 0, 5], 7), 11,'pairwise([1, 4, 2, 3, 0, 5], 7) should return 11.');" + "testString": "assert.deepEqual(pairwise([1, 4, 2, 3, 0, 5], 7), 11, 'pairwise([1, 4, 2, 3, 0, 5], 7) should return 11.');" }, { "text": "pairwise([1, 3, 2, 4], 4) should return 1.", - "testString": "assert.deepEqual(pairwise([1, 3, 2, 4], 4), 1,'pairwise([1, 3, 2, 4], 4) should return 1.');" + "testString": "assert.deepEqual(pairwise([1, 3, 2, 4], 4), 1, 'pairwise([1, 3, 2, 4], 4) should return 1.');" }, { "text": "pairwise([1, 1, 1], 2) should return 1.", - "testString": "assert.deepEqual(pairwise([1, 1, 1], 2), 1,'pairwise([1, 1, 1], 2) should return 1.');" + "testString": "assert.deepEqual(pairwise([1, 1, 1], 2), 1, 'pairwise([1, 1, 1], 2) should return 1.');" }, { "text": "pairwise([0, 0, 0, 0, 1, 1], 1) should return 10.", - "testString": "assert.deepEqual(pairwise([0, 0, 0, 0, 1, 1], 1), 10,'pairwise([0, 0, 0, 0, 1, 1], 1) should return 10.');" + "testString": "assert.deepEqual(pairwise([0, 0, 0, 0, 1, 1], 1), 10, 'pairwise([0, 0, 0, 0, 1, 1], 1) should return 10.');" }, { "text": "pairwise([], 100) should return 0.", - "testString": "assert.deepEqual(pairwise([], 100), 0,'pairwise([], 100) should return 0.');" + "testString": "assert.deepEqual(pairwise([], 100), 0, 'pairwise([], 100) should return 0.');" } ], "MDNlinks": [ @@ -292,7 +292,7 @@ "name": "index", "contents": [ "function pairwise(arr, arg) {", - "return arg;", + " return arg;", "}", "", "pairwise([1,4,2,3,0,5], 7);" @@ -307,7 +307,7 @@ "title": "Implement Bubble Sort", "description": [ "This is the first of several challenges on sorting algorithms. Given an array of unsorted items, we want to be able to return a sorted array. We will see several different methods to do this and learn some tradeoffs between these different approaches. While most modern languages have built-in sorting methods for operations like this, it is still important to understand some of the common basic approaches and learn how they can be implemented.", - "Here we will see bubble sort. The bubble sort method starts at the beginning of an unsorted array and'bubbles up'unsorted values towards the end, iterating through the array until it is completely sorted. It does this by comparing adjacent items and swapping them if they are out of order. The method continues looping through the array until no swaps occur at which point the array is sorted.", + "Here we will see bubble sort. The bubble sort method starts at the beginning of an unsorted array and 'bubbles up' unsorted values towards the end, iterating through the array until it is completely sorted. It does this by comparing adjacent items and swapping them if they are out of order. The method continues looping through the array until no swaps occur at which point the array is sorted.", "This method requires multiple iterations through the array and for average and worst cases has quadratic time complexity. While simple, it is usually impractical in most situations.", "Instructions: Write a function bubbleSort which takes an array of integers as input and returns an array of these integers in sorted order from least to greatest.", "Note:
We are calling this function from behind the scenes; the test array we are using is commented out in the editor. Try logging array to see your sorting algorithm in action!" @@ -315,19 +315,19 @@ "tests": [ { "text": "bubbleSort is a function.", - "testString": "assert(typeof bubbleSort =='function','bubbleSort is a function.');" + "testString": "assert(typeof bubbleSort == 'function', 'bubbleSort is a function.');" }, { "text": "bubbleSort returns a sorted array (least to greatest).", - "testString": "assert(isSorted(bubbleSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])),'bubbleSort returns a sorted array (least to greatest).');" + "testString": "assert(isSorted(bubbleSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])), 'bubbleSort returns a sorted array (least to greatest).');" }, { "text": "bubbleSort returns an array that is unchanged except for order.", - "testString": "assert.sameMembers(bubbleSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92],'bubbleSort returns an array that is unchanged except for order.');" + "testString": "assert.sameMembers(bubbleSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92], 'bubbleSort returns an array that is unchanged except for order.');" }, { "text": "bubbleSort should not use the built-in .sort() method.", - "testString": "assert.strictEqual(code.search(/\\.sort\\(/), -1,'bubbleSort should not use the built-in .sort() method.');" + "testString": "assert.strictEqual(code.search(/\\.sort\\(/), -1, 'bubbleSort should not use the built-in .sort() method.');" } ], "solutions": [], @@ -340,10 +340,10 @@ "name": "index", "contents": [ "function bubbleSort(array) {", - "// change code below this line", + " // change code below this line", "", - "// change code above this line", - "return array;", + " // change code above this line", + " return array;", "}", "", "// test array:", @@ -352,8 +352,8 @@ "head": [], "tail": [ "function isSorted(arr) {", - "var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1);", - "return check(0);", + " var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1);", + " return check(0);", "};" ] } @@ -370,19 +370,19 @@ "tests": [ { "text": "selectionSort is a function.", - "testString": "assert(typeof selectionSort =='function','selectionSort is a function.');" + "testString": "assert(typeof selectionSort == 'function', 'selectionSort is a function.');" }, { "text": "selectionSort returns a sorted array (least to greatest).", - "testString": "assert(isSorted(selectionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])),'selectionSort returns a sorted array (least to greatest).');" + "testString": "assert(isSorted(selectionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])), 'selectionSort returns a sorted array (least to greatest).');" }, { "text": "selectionSort returns an array that is unchanged except for order.", - "testString": "assert.sameMembers(selectionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92],'selectionSort returns an array that is unchanged except for order.');" + "testString": "assert.sameMembers(selectionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92], 'selectionSort returns an array that is unchanged except for order.');" }, { "text": "selectionSort should not use the built-in .sort() method.", - "testString": "assert.strictEqual(code.search(/\\.sort\\(/), -1,'selectionSort should not use the built-in .sort() method.');" + "testString": "assert.strictEqual(code.search(/\\.sort\\(/), -1, 'selectionSort should not use the built-in .sort() method.');" } ], "solutions": [], @@ -395,10 +395,10 @@ "name": "index", "contents": [ "function selectionSort(array) {", - "// change code below this line", + " // change code below this line", "", - "// change code above this line", - "return array;", + " // change code above this line", + " return array;", "}", "", "// test array:", @@ -407,8 +407,8 @@ "head": [], "tail": [ "function isSorted(arr) {", - "var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1);", - "return check(0);", + " var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1);", + " return check(0);", "};" ] } @@ -425,19 +425,19 @@ "tests": [ { "text": "insertionSort is a function.", - "testString": "assert(typeof insertionSort =='function','insertionSort is a function.');" + "testString": "assert(typeof insertionSort == 'function', 'insertionSort is a function.');" }, { "text": "insertionSort returns a sorted array (least to greatest).", - "testString": "assert(isSorted(insertionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])),'insertionSort returns a sorted array (least to greatest).');" + "testString": "assert(isSorted(insertionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])), 'insertionSort returns a sorted array (least to greatest).');" }, { "text": "insertionSort returns an array that is unchanged except for order.", - "testString": "assert.sameMembers(insertionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92],'insertionSort returns an array that is unchanged except for order.');" + "testString": "assert.sameMembers(insertionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92], 'insertionSort returns an array that is unchanged except for order.');" }, { "text": "insertionSort should not use the built-in .sort() method.", - "testString": "assert.strictEqual(code.search(/\\.sort\\(/), -1,'insertionSort should not use the built-in .sort() method.');" + "testString": "assert.strictEqual(code.search(/\\.sort\\(/), -1, 'insertionSort should not use the built-in .sort() method.');" } ], "solutions": [], @@ -450,10 +450,10 @@ "name": "index", "contents": [ "function insertionSort(array) {", - "// change code below this line", + " // change code below this line", "", - "// change code above this line", - "return array;", + " // change code above this line", + " return array;", "}", "", "// test array:", @@ -462,8 +462,8 @@ "head": [], "tail": [ "function isSorted(arr) {", - "var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1);", - "return check(0);", + " var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1);", + " return check(0);", "};" ] } @@ -481,19 +481,19 @@ "tests": [ { "text": "quickSort is a function.", - "testString": "assert(typeof quickSort =='function','quickSort is a function.');" + "testString": "assert(typeof quickSort == 'function', 'quickSort is a function.');" }, { "text": "quickSort returns a sorted array (least to greatest).", - "testString": "assert(isSorted(quickSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])),'quickSort returns a sorted array (least to greatest).');" + "testString": "assert(isSorted(quickSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])), 'quickSort returns a sorted array (least to greatest).');" }, { "text": "quickSort returns an array that is unchanged except for order.", - "testString": "assert.sameMembers(quickSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92],'quickSort returns an array that is unchanged except for order.');" + "testString": "assert.sameMembers(quickSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92], 'quickSort returns an array that is unchanged except for order.');" }, { "text": "quickSort should not use the built-in .sort() method.", - "testString": "assert.strictEqual(code.search(/\\.sort\\(/), -1,'quickSort should not use the built-in .sort() method.');" + "testString": "assert.strictEqual(code.search(/\\.sort\\(/), -1, 'quickSort should not use the built-in .sort() method.');" } ], "solutions": [], @@ -506,10 +506,10 @@ "name": "index", "contents": [ "function quickSort(array) {", - "// change code below this line", + " // change code below this line", "", - "// change code above this line", - "return array;", + " // change code above this line", + " return array;", "}", "", "// test array:", @@ -518,8 +518,8 @@ "head": [], "tail": [ "function isSorted(arr) {", - "var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1);", - "return check(0);", + " var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1);", + " return check(0);", "};" ] } @@ -540,19 +540,19 @@ "tests": [ { "text": "mergeSort is a function.", - "testString": "assert(typeof mergeSort =='function','mergeSort is a function.');" + "testString": "assert(typeof mergeSort == 'function', 'mergeSort is a function.');" }, { "text": "mergeSort returns a sorted array (least to greatest).", - "testString": "assert(isSorted(mergeSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])),'mergeSort returns a sorted array (least to greatest).');" + "testString": "assert(isSorted(mergeSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])), 'mergeSort returns a sorted array (least to greatest).');" }, { "text": "mergeSort returns an array that is unchanged except for order.", - "testString": "assert.sameMembers(mergeSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92],'mergeSort returns an array that is unchanged except for order.');" + "testString": "assert.sameMembers(mergeSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92], 'mergeSort returns an array that is unchanged except for order.');" }, { "text": "mergeSort should not use the built-in .sort() method.", - "testString": "assert.strictEqual(code.search(/\\.sort\\(/), -1,'mergeSort should not use the built-in .sort() method.');" + "testString": "assert.strictEqual(code.search(/\\.sort\\(/), -1, 'mergeSort should not use the built-in .sort() method.');" } ], "solutions": [], @@ -565,10 +565,10 @@ "name": "index", "contents": [ "function mergeSort(array) {", - "// change code below this line", + " // change code below this line", "", - "// change code above this line", - "return array;", + " // change code above this line", + " return array;", "}", "", "// test array:", @@ -577,8 +577,8 @@ "head": [], "tail": [ "function isSorted(arr) {", - "var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1);", - "return check(0);", + " var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1);", + " return check(0);", "};" ] }