From 5e5d10131d3689cbdf5544532daab7a3b10b875f Mon Sep 17 00:00:00 2001 From: LynnLian Date: Tue, 31 Jul 2018 21:31:48 +0200 Subject: [PATCH 1/4] Re-push commit --- ...gorithms-and-data-structures-projects.json | 356 +++++++++--------- 1 file changed, 178 insertions(+), 178 deletions(-) diff --git a/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects.json b/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects.json index 7170145..ab46cbc 100644 --- a/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects.json +++ b/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects.json @@ -8,65 +8,65 @@ "id": "aaa48de84e1ecc7c742e1124", "title": "Palindrome Checker", "description": [ - "Return true if the given string is a palindrome. Otherwise, return false.", - "A palindrome is a word or sentence that's spelled the same way both forward and backward, ignoring punctuation, case, and spacing.", - "Note
You'll need to remove all non-alphanumeric characters (punctuation, spaces and symbols) and turn everything into the same case (lower or upper case) in order to check for palindromes.", - "We'll pass strings with varying formats, such as \"racecar\", \"RaceCar\", and \"race CAR\" among others.", - "We'll also pass strings with special symbols, such as \"2A3*3a2\", \"2A3 3a2\", and \"2_A3*3#A2\".", - "Remember to use Read-Search-Ask if you get stuck. Write your own code." + "如果给定的一个字符串是回文,那么返回true,否则返回false。", + "palindrome(回文),指在忽略标点符号、大小写和空格的前提下,正着读和反着读一模一样。", + "注意:
检查回文时,你需要先除去所有非字母数字的字符(标点、空格和符号)并且将所有字符转换成字母大写或字母小写。", + "我们将会传入不同格式的字符串,例如:\"racecar\"\"RaceCar\"\"race CAR\"等等。", + "我们也会传入一些包含特殊符号的字符串,例如\"2A3*3a2\"\"2A3 3a2\"\"2_A3*3#A2\"。", + "如果你遇到了问题,请点击帮助。" ], "tests": [ { - "text": "palindrome(\"eye\") should return a boolean.", - "testString": "assert(typeof palindrome(\"eye\") === \"boolean\", 'palindrome(\"eye\") should return a boolean.');" + "text": "palindrome(\"eye\")应该返回一个布尔值。", + "testString": "assert(typeof palindrome(\"eye\") === \"boolean\", 'palindrome(\"eye\")应该返回一个布尔值。');" }, { - "text": "palindrome(\"eye\") should return true.", - "testString": "assert(palindrome(\"eye\") === true, 'palindrome(\"eye\") should return true.');" + "text": "palindrome(\"eye\")应该返回 true。", + "testString": "assert(palindrome(\"eye\") === true, 'palindrome(\"eye\")应该返回 true。');" }, { - "text": "palindrome(\"_eye\") should return true.", - "testString": "assert(palindrome(\"_eye\") === true, 'palindrome(\"_eye\") should return true.');" + "text": "palindrome(\"_eye\")应该返回 true。", + "testString": "assert(palindrome(\"_eye\") === true, 'palindrome(\"_eye\")应该返回 true。');" }, { - "text": "palindrome(\"race car\") should return true.", - "testString": "assert(palindrome(\"race car\") === true, 'palindrome(\"race car\") should return true.');" + "text": "palindrome(\"race car\")应该返回 true。", + "testString": "assert(palindrome(\"race car\") === true, 'palindrome(\"race car\")应该返回 true。');" }, { - "text": "palindrome(\"not a palindrome\") should return false.", - "testString": "assert(palindrome(\"not a palindrome\") === false, 'palindrome(\"not a palindrome\") should return false.');" + "text": "palindrome(\"not a palindrome\")应该返回 false。", + "testString": "assert(palindrome(\"not a palindrome\") === false, 'palindrome(\"not a palindrome\")应该返回 false。');" }, { - "text": "palindrome(\"A man, a plan, a canal. Panama\") should return true.", - "testString": "assert(palindrome(\"A man, a plan, a canal. Panama\") === true, 'palindrome(\"A man, a plan, a canal. Panama\") should return true.');" + "text": "palindrome(\"A man, a plan, a canal. Panama\")应该返回 true。", + "testString": "assert(palindrome(\"A man, a plan, a canal. Panama\") === true, 'palindrome(\"A man, a plan, a canal. Panama\")应该返回 true。');" }, { - "text": "palindrome(\"never odd or even\") should return true.", - "testString": "assert(palindrome(\"never odd or even\") === true, 'palindrome(\"never odd or even\") should return true.');" + "text": "palindrome(\"never odd or even\")应该返回 true。", + "testString": "assert(palindrome(\"never odd or even\") === true, 'palindrome(\"never odd or even\")应该返回 true。');" }, { - "text": "palindrome(\"nope\") should return false.", - "testString": "assert(palindrome(\"nope\") === false, 'palindrome(\"nope\") should return false.');" + "text": "palindrome(\"nope\")应该返回 false。", + "testString": "assert(palindrome(\"nope\") === false, 'palindrome(\"nope\")应该返回 false。');" }, { - "text": "palindrome(\"almostomla\") should return false.", - "testString": "assert(palindrome(\"almostomla\") === false, 'palindrome(\"almostomla\") should return false.');" + "text": "palindrome(\"almostomla\")应该返回 false。", + "testString": "assert(palindrome(\"almostomla\") === false, 'palindrome(\"almostomla\")应该返回 false。');" }, { - "text": "palindrome(\"My age is 0, 0 si ega ym.\") should return true.", - "testString": "assert(palindrome(\"My age is 0, 0 si ega ym.\") === true, 'palindrome(\"My age is 0, 0 si ega ym.\") should return true.');" + "text": "palindrome(\"My age is 0, 0 si ega ym.\")应该返回 true。", + "testString": "assert(palindrome(\"My age is 0, 0 si ega ym.\") === true, 'palindrome(\"My age is 0, 0 si ega ym.\")应该返回 true。');" }, { - "text": "palindrome(\"1 eye for of 1 eye.\") should return false.", - "testString": "assert(palindrome(\"1 eye for of 1 eye.\") === false, 'palindrome(\"1 eye for of 1 eye.\") should return false.');" + "text": "palindrome(\"1 eye for of 1 eye.\")应该返回 false。", + "testString": "assert(palindrome(\"1 eye for of 1 eye.\") === false, 'palindrome(\"1 eye for of 1 eye.\")应该返回 false。');" }, { - "text": "palindrome(\"0_0 (: /-\\ :) 0-0\") should return true.", - "testString": "assert(palindrome(\"0_0 (: /-\\ :) 0-0\") === true, 'palindrome(\"0_0 (: /-\\ :) 0-0\") should return true.');" + "text": "palindrome(\"0_0 (: /-\\ :) 0-0\")应该返回 true。", + "testString": "assert(palindrome(\"0_0 (: /-\\ :) 0-0\") === true, 'palindrome(\"0_0 (: /-\\ :) 0-0\")应该返回 true。');" }, { - "text": "palindrome(\"five|\\_/|four\") should return false.", - "testString": "assert(palindrome(\"five|\\_/|four\") === false, 'palindrome(\"five|\\_/|four\") should return false.');" + "text": "palindrome(\"five|\\_/|four\")应该返回 false。", + "testString": "assert(palindrome(\"five|\\_/|four\") === false, 'palindrome(\"five|\\_/|four\")应该返回 false。');" } ], "isRequired": true, @@ -102,117 +102,117 @@ "id": "a7f4d8f2483413a6ce226cac", "title": "Roman Numeral Converter", "description": [ - "Convert the given number into a roman numeral.", - "All roman numerals answers should be provided in upper-case.", - "Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code." + "把传入的数字转变为罗马数字。", + "转换后的罗马数字字母必须都是大写。", + "如果你遇到了问题,请点击帮助。" ], "solutions": [ "function convertToRoman(num) {\n var ref = [['M', 1000], ['CM', 900], ['D', 500], ['CD', 400], ['C', 100], ['XC', 90], ['L', 50], ['XL', 40], ['X', 10], ['IX', 9], ['V', 5], ['IV', 4], ['I', 1]];\n var res = [];\n ref.forEach(function(p) {\n while (num >= p[1]) {\n res.push(p[0]);\n num -= p[1];\n }\n });\n return res.join('');\n}" ], "tests": [ { - "text": "convertToRoman(2) should return \"II\".", - "testString": "assert.deepEqual(convertToRoman(2), \"II\", 'convertToRoman(2) should return \"II\".');" + "text": "convertToRoman(2)应该返回 \"II\"。", + "testString": "assert.deepEqual(convertToRoman(2), \"II\", 'convertToRoman(2)应该返回 \"II\"。');" }, { - "text": "convertToRoman(3) should return \"III\".", - "testString": "assert.deepEqual(convertToRoman(3), \"III\", 'convertToRoman(3) should return \"III\".');" + "text": "convertToRoman(3)应该返回 \"III\"。", + "testString": "assert.deepEqual(convertToRoman(3), \"III\", 'convertToRoman(3)应该返回 \"III\"。');" }, { - "text": "convertToRoman(4) should return \"IV\".", - "testString": "assert.deepEqual(convertToRoman(4), \"IV\", 'convertToRoman(4) should return \"IV\".');" + "text": "convertToRoman(4)应该返回 \"IV\"。", + "testString": "assert.deepEqual(convertToRoman(4), \"IV\", 'convertToRoman(4)应该返回 \"IV\"。');" }, { - "text": "convertToRoman(5) should return \"V\".", - "testString": "assert.deepEqual(convertToRoman(5), \"V\", 'convertToRoman(5) should return \"V\".');" + "text": "convertToRoman(5)应该返回 \"V\"。", + "testString": "assert.deepEqual(convertToRoman(5), \"V\", 'convertToRoman(5)应该返回 \"V\"。');" }, { - "text": "convertToRoman(9) should return \"IX\".", - "testString": "assert.deepEqual(convertToRoman(9), \"IX\", 'convertToRoman(9) should return \"IX\".');" + "text": "convertToRoman(9)应该返回 \"IX\"。", + "testString": "assert.deepEqual(convertToRoman(9), \"IX\", 'convertToRoman(9)应该返回 \"IX\"。');" }, { - "text": "convertToRoman(12) should return \"XII\".", - "testString": "assert.deepEqual(convertToRoman(12), \"XII\", 'convertToRoman(12) should return \"XII\".');" + "text": "convertToRoman(12)应该返回 \"XII\"。", + "testString": "assert.deepEqual(convertToRoman(12), \"XII\", 'convertToRoman(12)应该返回 \"XII\"。');" }, { - "text": "convertToRoman(16) should return \"XVI\".", - "testString": "assert.deepEqual(convertToRoman(16), \"XVI\", 'convertToRoman(16) should return \"XVI\".');" + "text": "convertToRoman(16)应该返回 \"XVI\"。", + "testString": "assert.deepEqual(convertToRoman(16), \"XVI\", 'convertToRoman(16)应该返回 \"XVI\"。');" }, { - "text": "convertToRoman(29) should return \"XXIX\".", - "testString": "assert.deepEqual(convertToRoman(29), \"XXIX\", 'convertToRoman(29) should return \"XXIX\".');" + "text": "convertToRoman(29)应该返回 \"XXIX\"。", + "testString": "assert.deepEqual(convertToRoman(29), \"XXIX\", 'convertToRoman(29)应该返回 \"XXIX\"。');" }, { - "text": "convertToRoman(44) should return \"XLIV\".", - "testString": "assert.deepEqual(convertToRoman(44), \"XLIV\", 'convertToRoman(44) should return \"XLIV\".');" + "text": "convertToRoman(44)应该返回 \"XLIV\"。", + "testString": "assert.deepEqual(convertToRoman(44), \"XLIV\", 'convertToRoman(44)应该返回 \"XLIV\"。');" }, { - "text": "convertToRoman(45) should return \"XLV\"", - "testString": "assert.deepEqual(convertToRoman(45), \"XLV\", 'convertToRoman(45) should return \"XLV\"');" + "text": "convertToRoman(45)应该返回 \"XLV\"。", + "testString": "assert.deepEqual(convertToRoman(45), \"XLV\", 'convertToRoman(45)应该返回 \"XLV\"。');" }, { - "text": "convertToRoman(68) should return \"LXVIII\"", - "testString": "assert.deepEqual(convertToRoman(68), \"LXVIII\", 'convertToRoman(68) should return \"LXVIII\"');" + "text": "convertToRoman(68)应该返回 \"LXVIII\"。", + "testString": "assert.deepEqual(convertToRoman(68), \"LXVIII\", 'convertToRoman(68)应该返回 \"LXVIII\"。');" }, { - "text": "convertToRoman(83) should return \"LXXXIII\"", - "testString": "assert.deepEqual(convertToRoman(83), \"LXXXIII\", 'convertToRoman(83) should return \"LXXXIII\"');" + "text": "convertToRoman(83)应该返回 \"LXXXIII\"。", + "testString": "assert.deepEqual(convertToRoman(83), \"LXXXIII\", 'convertToRoman(83)应该返回 \"LXXXIII\"。');" }, { - "text": "convertToRoman(97) should return \"XCVII\"", - "testString": "assert.deepEqual(convertToRoman(97), \"XCVII\", 'convertToRoman(97) should return \"XCVII\"');" + "text": "convertToRoman(97)应该返回 \"XCVII\"。", + "testString": "assert.deepEqual(convertToRoman(97), \"XCVII\", 'convertToRoman(97)应该返回 \"XCVII\"。');" }, { - "text": "convertToRoman(99) should return \"XCIX\"", - "testString": "assert.deepEqual(convertToRoman(99), \"XCIX\", 'convertToRoman(99) should return \"XCIX\"');" + "text": "convertToRoman(99)应该返回 \"XCIX\"。", + "testString": "assert.deepEqual(convertToRoman(99), \"XCIX\", 'convertToRoman(99)应该返回 \"XCIX\"。');" }, { - "text": "convertToRoman(400) should return \"CD\"", - "testString": "assert.deepEqual(convertToRoman(400), \"CD\", 'convertToRoman(400) should return \"CD\"');" + "text": "convertToRoman(400)应该返回 \"CD\"。", + "testString": "assert.deepEqual(convertToRoman(400), \"CD\", 'convertToRoman(400)应该返回 \"CD\"。');" }, { - "text": "convertToRoman(500) should return \"D\"", - "testString": "assert.deepEqual(convertToRoman(500), \"D\", 'convertToRoman(500) should return \"D\"');" + "text": "convertToRoman(500)应该返回 \"D\"。", + "testString": "assert.deepEqual(convertToRoman(500), \"D\", 'convertToRoman(500)应该返回 \"D\"。');" }, { - "text": "convertToRoman(501) should return \"DI\"", - "testString": "assert.deepEqual(convertToRoman(501), \"DI\", 'convertToRoman(501) should return \"DI\"');" + "text": "convertToRoman(501)应该返回 \"DI\"。", + "testString": "assert.deepEqual(convertToRoman(501), \"DI\", 'convertToRoman(501)应该返回 \"DI\"。');" }, { - "text": "convertToRoman(649) should return \"DCXLIX\"", - "testString": "assert.deepEqual(convertToRoman(649), \"DCXLIX\", 'convertToRoman(649) should return \"DCXLIX\"');" + "text": "convertToRoman(649)应该返回 \"DCXLIX\"。", + "testString": "assert.deepEqual(convertToRoman(649), \"DCXLIX\", 'convertToRoman(649)应该返回 \"DCXLIX\"。');" }, { - "text": "convertToRoman(798) should return \"DCCXCVIII\"", - "testString": "assert.deepEqual(convertToRoman(798), \"DCCXCVIII\", 'convertToRoman(798) should return \"DCCXCVIII\"');" + "text": "convertToRoman(798)应该返回 \"DCCXCVIII\"。", + "testString": "assert.deepEqual(convertToRoman(798), \"DCCXCVIII\", 'convertToRoman(798)应该返回 \"DCCXCVIII\"。');" }, { - "text": "convertToRoman(891) should return \"DCCCXCI\"", - "testString": "assert.deepEqual(convertToRoman(891), \"DCCCXCI\", 'convertToRoman(891) should return \"DCCCXCI\"');" + "text": "convertToRoman(891)应该返回 \"DCCCXCI\"。", + "testString": "assert.deepEqual(convertToRoman(891), \"DCCCXCI\", 'convertToRoman(891)应该返回 \"DCCCXCI\"。');" }, { - "text": "convertToRoman(1000) should return \"M\"", - "testString": "assert.deepEqual(convertToRoman(1000), \"M\", 'convertToRoman(1000) should return \"M\"');" + "text": "convertToRoman(1000)应该返回 \"M\"。", + "testString": "assert.deepEqual(convertToRoman(1000), \"M\", 'convertToRoman(1000)应该返回 \"M\"。');" }, { - "text": "convertToRoman(1004) should return \"MIV\"", - "testString": "assert.deepEqual(convertToRoman(1004), \"MIV\", 'convertToRoman(1004) should return \"MIV\"');" + "text": "convertToRoman(1004)应该返回 \"MIV\"。", + "testString": "assert.deepEqual(convertToRoman(1004), \"MIV\", 'convertToRoman(1004)应该返回 \"MIV\"。');" }, { - "text": "convertToRoman(1006) should return \"MVI\"", - "testString": "assert.deepEqual(convertToRoman(1006), \"MVI\", 'convertToRoman(1006) should return \"MVI\"');" + "text": "convertToRoman(1006)应该返回 \"MVI\"。", + "testString": "assert.deepEqual(convertToRoman(1006), \"MVI\", 'convertToRoman(1006)应该返回 \"MVI\"。');" }, { - "text": "convertToRoman(1023) should return \"MXXIII\"", - "testString": "assert.deepEqual(convertToRoman(1023), \"MXXIII\", 'convertToRoman(1023) should return \"MXXIII\"');" + "text": "convertToRoman(1023)应该返回 \"MXXIII\"。", + "testString": "assert.deepEqual(convertToRoman(1023), \"MXXIII\", 'convertToRoman(1023)应该返回 \"MXXIII\"。');" }, { - "text": "convertToRoman(2014) should return \"MMXIV\"", - "testString": "assert.deepEqual(convertToRoman(2014), \"MMXIV\", 'convertToRoman(2014) should return \"MMXIV\"');" + "text": "convertToRoman(2014)应该返回 \"MMXIV\"。", + "testString": "assert.deepEqual(convertToRoman(2014), \"MMXIV\", 'convertToRoman(2014)应该返回 \"MMXIV\"。');" }, { - "text": "convertToRoman(3999) should return \"MMMCMXCIX\"", - "testString": "assert.deepEqual(convertToRoman(3999), \"MMMCMXCIX\", 'convertToRoman(3999) should return \"MMMCMXCIX\"');" + "text": "convertToRoman(3999)应该返回 \"MMMCMXCIX\"。", + "testString": "assert.deepEqual(convertToRoman(3999), \"MMMCMXCIX\", 'convertToRoman(3999)应该返回 \"MMMCMXCIX\"。');" } ], "MDNlinks": [ @@ -244,31 +244,31 @@ "id": "56533eb9ac21ba0edf2244e2", "title": "Caesars Cipher", "description": [ - "One of the simplest and most widely known ciphers is a Caesar cipher, also known as a shift cipher. In a shift cipher the meanings of the letters are shifted by some set amount.", - "A common modern use is the ROT13 cipher, where the values of the letters are shifted by 13 places. Thus 'A' ↔ 'N', 'B' ↔ 'O' and so on.", - "Write a function which takes a ROT13 encoded string as input and returns a decoded string.", - "All letters will be uppercase. Do not transform any non-alphabetic character (i.e. spaces, punctuation), but do pass them on.", - "Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code." + "世界上最简单、最著名的加密方法凯撒密码,也叫移位密码。在移位密码中,明文中的字母通过按照一个固定数目进行偏移后被替换成新的字母。", + "ROT13 是一个被广泛使用的编码技术,明文中的所有字母都被移动 13 位。因此,'A' ↔ 'N', 'B' ↔ 'O' 等等。", + "请编写一个函数,用于解码一个被 ROT13 编码的字符串,然后返回解码后的结果。", + "所有解码后的字母都必须为字母大写。请不要解码非字母的字符(例如,空格、标点符号),但你需要在结果中保留它们。", + "如果你遇到了问题,请点击帮助。" ], "solutions": [ "var lookup = {\n 'A': 'N','B': 'O','C': 'P','D': 'Q',\n 'E': 'R','F': 'S','G': 'T','H': 'U',\n 'I': 'V','J': 'W','K': 'X','L': 'Y',\n 'M': 'Z','N': 'A','O': 'B','P': 'C',\n 'Q': 'D','R': 'E','S': 'F','T': 'G',\n 'U': 'H','V': 'I','W': 'J','X': 'K',\n 'Y': 'L','Z': 'M' \n};\n\nfunction rot13(encodedStr) {\n var codeArr = encodedStr.split(\"\"); // String to Array\n var decodedArr = []; // Your Result goes here\n // Only change code below this line\n \n decodedArr = codeArr.map(function(letter) {\n if(lookup.hasOwnProperty(letter)) {\n letter = lookup[letter];\n }\n return letter;\n });\n\n // Only change code above this line\n return decodedArr.join(\"\"); // Array to String\n}" ], "tests": [ { - "text": "rot13(\"SERR PBQR PNZC\") should decode to FREE CODE CAMP", - "testString": "assert(rot13(\"SERR PBQR PNZC\") === \"FREE CODE CAMP\", 'rot13(\"SERR PBQR PNZC\") should decode to FREE CODE CAMP');" + "text": "rot13(\"SERR PBQR PNZC\")应解码为FREE CODE CAMP。", + "testString": "assert(rot13(\"SERR PBQR PNZC\") === \"FREE CODE CAMP\", 'rot13(\"SERR PBQR PNZC\")应解码为FREE CODE CAMP。');" }, { - "text": "rot13(\"SERR CVMMN!\") should decode to FREE PIZZA!", - "testString": "assert(rot13(\"SERR CVMMN!\") === \"FREE PIZZA!\", 'rot13(\"SERR CVMMN!\") should decode to FREE PIZZA!');" + "text": "rot13(\"SERR CVMMN!\")应解码为FREE PIZZA!。", + "testString": "assert(rot13(\"SERR CVMMN!\") === \"FREE PIZZA!\", 'rot13(\"SERR CVMMN!\")应解码为FREE PIZZA!。');" }, { - "text": "rot13(\"SERR YBIR?\") should decode to FREE LOVE?", - "testString": "assert(rot13(\"SERR YBIR?\") === \"FREE LOVE?\", 'rot13(\"SERR YBIR?\") should decode to FREE LOVE?');" + "text": "rot13(\"SERR YBIR?\")应解码为FREE LOVE?。", + "testString": "assert(rot13(\"SERR YBIR?\") === \"FREE LOVE?\", 'rot13(\"SERR YBIR?\")应解码为FREE LOVE?。');" }, { - "text": "rot13(\"GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT.\") should decode to THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.", - "testString": "assert(rot13(\"GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT.\") === \"THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.\", 'rot13(\"GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT.\") should decode to THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.');" + "text": "rot13(\"GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT.\")应解码为THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.。", + "testString": "assert(rot13(\"GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT.\") === \"THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.\", 'rot13(\"GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT.\")应解码为THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.。');" } ], "MDNlinks": [ @@ -301,123 +301,123 @@ "id": "aff0395860f5d3034dc0bfc9", "title": "Telephone Number Validator", "description": [ - "Return true if the passed string looks like a valid US phone number.", - "The user may fill out the form field any way they choose as long as it has the format of a valid US number. The following are examples of valid formats for US numbers (refer to the tests below for other variants):", + "如果传入的字符串是一个有效的美国电话号码格式,则返回true。", + "只要是有效的美国电话号码的格式,用户可以按照他们的方式填写表单中的电话号码。以下是一些正确的例子(其他格式变形请参考以下例子):", "
555-555-5555
(555)555-5555
(555) 555-5555
555 555 5555
5555555555
1 555 555 5555
", - "For this challenge you will be presented with a string such as 800-692-7753 or 8oo-six427676;laskdjf. Your job is to validate or reject the US phone number based on any combination of the formats provided above. The area code is required. If the country code is provided, you must confirm that the country code is 1. Return true if the string is a valid US phone number; otherwise return false.", - "Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code." + "在这个挑战中,你将会看到例如800-692-7753或者8oo-six427676;laskdjf的号码。你的任务是根据上面不同的格式组合,判断它是否美国号码。区号是必须的。如果提供国家代码,则必须确认国家代码为1。如果这是有效的美国电话就返回true,否则返回false。", + "如果你遇到了问题,请点击帮助。" ], "solutions": [ "var re = /^([+]?1[\\s]?)?((?:[(](?:[2-9]1[02-9]|[2-9][02-8][0-9])[)][\\s]?)|(?:(?:[2-9]1[02-9]|[2-9][02-8][0-9])[\\s.-]?)){1}([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2}[\\s.-]?){1}([0-9]{4}){1}$/;\n\nfunction telephoneCheck(str) {\n return re.test(str);\n}\n\ntelephoneCheck(\"555-555-5555\");" ], "tests": [ { - "text": "telephoneCheck(\"555-555-5555\") should return a boolean.", - "testString": "assert(typeof telephoneCheck(\"555-555-5555\") === \"boolean\", 'telephoneCheck(\"555-555-5555\") should return a boolean.');" + "text": "telephoneCheck(\"555-555-5555\")应该返回布尔值。", + "testString": "assert(typeof telephoneCheck(\"555-555-5555\") === \"boolean\", 'telephoneCheck(\"555-555-5555\")应该返回布尔值。');" }, { - "text": "telephoneCheck(\"1 555-555-5555\") should return true.", - "testString": "assert(telephoneCheck(\"1 555-555-5555\") === true, 'telephoneCheck(\"1 555-555-5555\") should return true.');" + "text": "telephoneCheck(\"1 555-555-5555\")应该返回 true。", + "testString": "assert(telephoneCheck(\"1 555-555-5555\") === true, 'telephoneCheck(\"1 555-555-5555\")应该返回 true。');" }, { - "text": "telephoneCheck(\"1 (555) 555-5555\") should return true.", - "testString": "assert(telephoneCheck(\"1 (555) 555-5555\") === true, 'telephoneCheck(\"1 (555) 555-5555\") should return true.');" + "text": "telephoneCheck(\"1 (555) 555-5555\")应该返回 true。", + "testString": "assert(telephoneCheck(\"1 (555) 555-5555\") === true, 'telephoneCheck(\"1 (555) 555-5555\")应该返回 true。');" }, { - "text": "telephoneCheck(\"5555555555\") should return true.", - "testString": "assert(telephoneCheck(\"5555555555\") === true, 'telephoneCheck(\"5555555555\") should return true.');" + "text": "telephoneCheck(\"5555555555\")应该返回 true。", + "testString": "assert(telephoneCheck(\"5555555555\") === true, 'telephoneCheck(\"5555555555\")应该返回 true。');" }, { - "text": "telephoneCheck(\"555-555-5555\") should return true.", - "testString": "assert(telephoneCheck(\"555-555-5555\") === true, 'telephoneCheck(\"555-555-5555\") should return true.');" + "text": "telephoneCheck(\"555-555-5555\")应该返回 true。", + "testString": "assert(telephoneCheck(\"555-555-5555\") === true, 'telephoneCheck(\"555-555-5555\")应该返回 true。');" }, { - "text": "telephoneCheck(\"(555)555-5555\") should return true.", - "testString": "assert(telephoneCheck(\"(555)555-5555\") === true, 'telephoneCheck(\"(555)555-5555\") should return true.');" + "text": "telephoneCheck(\"(555)555-5555\")应该返回 true。", + "testString": "assert(telephoneCheck(\"(555)555-5555\") === true, 'telephoneCheck(\"(555)555-5555\")应该返回 true。');" }, { - "text": "telephoneCheck(\"1(555)555-5555\") should return true.", - "testString": "assert(telephoneCheck(\"1(555)555-5555\") === true, 'telephoneCheck(\"1(555)555-5555\") should return true.');" + "text": "telephoneCheck(\"1(555)555-5555\")应该返回 true。", + "testString": "assert(telephoneCheck(\"1(555)555-5555\") === true, 'telephoneCheck(\"1(555)555-5555\")应该返回 true。');" }, { - "text": "telephoneCheck(\"555-5555\") should return false.", - "testString": "assert(telephoneCheck(\"555-5555\") === false, 'telephoneCheck(\"555-5555\") should return false.');" + "text": "telephoneCheck(\"555-5555\")应该返回 false。", + "testString": "assert(telephoneCheck(\"555-5555\") === false, 'telephoneCheck(\"555-5555\")应该返回 false。');" }, { - "text": "telephoneCheck(\"5555555\") should return false.", - "testString": "assert(telephoneCheck(\"5555555\") === false, 'telephoneCheck(\"5555555\") should return false.');" + "text": "telephoneCheck(\"5555555\")应该返回 false。", + "testString": "assert(telephoneCheck(\"5555555\") === false, 'telephoneCheck(\"5555555\")应该返回 false。');" }, { - "text": "telephoneCheck(\"1 555)555-5555\") should return false.", - "testString": "assert(telephoneCheck(\"1 555)555-5555\") === false, 'telephoneCheck(\"1 555)555-5555\") should return false.');" + "text": "telephoneCheck(\"1 555)555-5555\")应该返回 false。", + "testString": "assert(telephoneCheck(\"1 555)555-5555\") === false, 'telephoneCheck(\"1 555)555-5555\")应该返回 false。');" }, { - "text": "telephoneCheck(\"1 555 555 5555\") should return true.", - "testString": "assert(telephoneCheck(\"1 555 555 5555\") === true, 'telephoneCheck(\"1 555 555 5555\") should return true.');" + "text": "telephoneCheck(\"1 555 555 5555\")应该返回 true。", + "testString": "assert(telephoneCheck(\"1 555 555 5555\") === true, 'telephoneCheck(\"1 555 555 5555\")应该返回 true。');" }, { - "text": "telephoneCheck(\"1 456 789 4444\") should return true.", - "testString": "assert(telephoneCheck(\"1 456 789 4444\") === true, 'telephoneCheck(\"1 456 789 4444\") should return true.');" + "text": "telephoneCheck(\"1 456 789 4444\")应该返回 true。", + "testString": "assert(telephoneCheck(\"1 456 789 4444\") === true, 'telephoneCheck(\"1 456 789 4444\")应该返回 true。');" }, { - "text": "telephoneCheck(\"123**&!!asdf#\") should return false.", - "testString": "assert(telephoneCheck(\"123**&!!asdf#\") === false, 'telephoneCheck(\"123**&!!asdf#\") should return false.');" + "text": "telephoneCheck(\"123**&!!asdf#\")应该返回 false。", + "testString": "assert(telephoneCheck(\"123**&!!asdf#\") === false, 'telephoneCheck(\"123**&!!asdf#\")应该返回 false。');" }, { - "text": "telephoneCheck(\"55555555\") should return false.", - "testString": "assert(telephoneCheck(\"55555555\") === false, 'telephoneCheck(\"55555555\") should return false.');" + "text": "telephoneCheck(\"55555555\")应该返回 false。", + "testString": "assert(telephoneCheck(\"55555555\") === false, 'telephoneCheck(\"55555555\")应该返回 false。');" }, { - "text": "telephoneCheck(\"(6054756961)\") should return false", - "testString": "assert(telephoneCheck(\"(6054756961)\") === false, 'telephoneCheck(\"(6054756961)\") should return false');" + "text": "telephoneCheck(\"(6054756961)\")应该返回 false。", + "testString": "assert(telephoneCheck(\"(6054756961)\") === false, 'telephoneCheck(\"(6054756961)\")应该返回 false。');" }, { - "text": "telephoneCheck(\"2 (757) 622-7382\") should return false.", - "testString": "assert(telephoneCheck(\"2 (757) 622-7382\") === false, 'telephoneCheck(\"2 (757) 622-7382\") should return false.');" + "text": "telephoneCheck(\"2 (757) 622-7382\")应该返回 false。", + "testString": "assert(telephoneCheck(\"2 (757) 622-7382\") === false, 'telephoneCheck(\"2 (757) 622-7382\")应该返回 false。');" }, { - "text": "telephoneCheck(\"0 (757) 622-7382\") should return false.", - "testString": "assert(telephoneCheck(\"0 (757) 622-7382\") === false, 'telephoneCheck(\"0 (757) 622-7382\") should return false.');" + "text": "telephoneCheck(\"0 (757) 622-7382\")应该返回 false。", + "testString": "assert(telephoneCheck(\"0 (757) 622-7382\") === false, 'telephoneCheck(\"0 (757) 622-7382\")应该返回 false。');" }, { - "text": "telephoneCheck(\"-1 (757) 622-7382\") should return false", - "testString": "assert(telephoneCheck(\"-1 (757) 622-7382\") === false, 'telephoneCheck(\"-1 (757) 622-7382\") should return false');" + "text": "telephoneCheck(\"-1 (757) 622-7382\")应该返回 false。", + "testString": "assert(telephoneCheck(\"-1 (757) 622-7382\") === false, 'telephoneCheck(\"-1 (757) 622-7382\")应该返回 false。');" }, { - "text": "telephoneCheck(\"2 757 622-7382\") should return false.", - "testString": "assert(telephoneCheck(\"2 757 622-7382\") === false, 'telephoneCheck(\"2 757 622-7382\") should return false.');" + "text": "telephoneCheck(\"2 757 622-7382\")应该返回 false。", + "testString": "assert(telephoneCheck(\"2 757 622-7382\") === false, 'telephoneCheck(\"2 757 622-7382\")应该返回 false。');" }, { - "text": "telephoneCheck(\"10 (757) 622-7382\") should return false.", - "testString": "assert(telephoneCheck(\"10 (757) 622-7382\") === false, 'telephoneCheck(\"10 (757) 622-7382\") should return false.');" + "text": "telephoneCheck(\"10 (757) 622-7382\")应该返回 false。", + "testString": "assert(telephoneCheck(\"10 (757) 622-7382\") === false, 'telephoneCheck(\"10 (757) 622-7382\")应该返回 false。');" }, { - "text": "telephoneCheck(\"27576227382\") should return false.", - "testString": "assert(telephoneCheck(\"27576227382\") === false, 'telephoneCheck(\"27576227382\") should return false.');" + "text": "telephoneCheck(\"27576227382\")应该返回 false。", + "testString": "assert(telephoneCheck(\"27576227382\") === false, 'telephoneCheck(\"27576227382\")应该返回 false。');" }, { - "text": "telephoneCheck(\"(275)76227382\") should return false.", - "testString": "assert(telephoneCheck(\"(275)76227382\") === false, 'telephoneCheck(\"(275)76227382\") should return false.');" + "text": "telephoneCheck(\"(275)76227382\")应该返回 false。", + "testString": "assert(telephoneCheck(\"(275)76227382\") === false, 'telephoneCheck(\"(275)76227382\")应该返回 false。');" }, { - "text": "telephoneCheck(\"2(757)6227382\") should return false.", - "testString": "assert(telephoneCheck(\"2(757)6227382\") === false, 'telephoneCheck(\"2(757)6227382\") should return false.');" + "text": "telephoneCheck(\"2(757)6227382\")应该返回 false。", + "testString": "assert(telephoneCheck(\"2(757)6227382\") === false, 'telephoneCheck(\"2(757)6227382\")应该返回 false。');" }, { - "text": "telephoneCheck(\"2(757)622-7382\") should return false.", - "testString": "assert(telephoneCheck(\"2(757)622-7382\") === false, 'telephoneCheck(\"2(757)622-7382\") should return false.');" + "text": "telephoneCheck(\"2(757)622-7382\")应该返回 false。", + "testString": "assert(telephoneCheck(\"2(757)622-7382\") === false, 'telephoneCheck(\"2(757)622-7382\")应该返回 false。');" }, { - "text": "telephoneCheck(\"555)-555-5555\") should return false.", - "testString": "assert(telephoneCheck(\"555)-555-5555\") === false, 'telephoneCheck(\"555)-555-5555\") should return false.');" + "text": "telephoneCheck(\"555)-555-5555\")应该返回 false。", + "testString": "assert(telephoneCheck(\"555)-555-5555\") === false, 'telephoneCheck(\"555)-555-5555\")应该返回 false。');" }, { - "text": "telephoneCheck(\"(555-555-5555\") should return false.", - "testString": "assert(telephoneCheck(\"(555-555-5555\") === false, 'telephoneCheck(\"(555-555-5555\") should return false.');" + "text": "telephoneCheck(\"(555-555-5555\")应该返回 false。", + "testString": "assert(telephoneCheck(\"(555-555-5555\") === false, 'telephoneCheck(\"(555-555-5555\")应该返回 false。');" }, { - "text": "telephoneCheck(\"(555)5(55?)-5555\") should return false.", - "testString": "assert(telephoneCheck(\"(555)5(55?)-5555\") === false, 'telephoneCheck(\"(555)5(55?)-5555\") should return false.');" + "text": "telephoneCheck(\"(555)5(55?)-5555\")应该返回 false。", + "testString": "assert(telephoneCheck(\"(555)5(55?)-5555\") === false, 'telephoneCheck(\"(555)5(55?)-5555\")应该返回 false。');" } ], "MDNlinks": [ @@ -447,42 +447,42 @@ "id": "aa2e6f85cab2ab736c9a9b24", "title": "Cash Register", "description": [ - "Design a cash register drawer function checkCashRegister() that accepts purchase price as the first argument (price), payment as the second argument (cash), and cash-in-drawer (cid) as the third argument.", - "cid is a 2D array listing available currency.", - "The checkCashRegister() function should always return an object with a status key and a change key.", - "Return {status: \"INSUFFICIENT_FUNDS\", change: []} if cash-in-drawer is less than the change due, or if you cannot return the exact change.", - "Return {status: \"CLOSED\", change: [...]} with cash-in-drawer as the value for the key change if it is equal to the change due.", - "Otherwise, return {status: \"OPEN\", change: [...]}, with the change due in coins and bills, sorted in highest to lowest order, as the value of the change key.", - "Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.", - "
Currency UnitAmount
Penny$0.01 (PENNY)
Nickel$0.05 (NICKEL)
Dime$0.1 (DIME)
Quarter$0.25 (QUARTER)
Dollar$1 (DOLLAR)
Five Dollars$5 (FIVE)
Ten Dollars$10 (TEN)
Twenty Dollars$20 (TWENTY)
One-hundred Dollars$100 (ONE HUNDRED)
" + "编写一个用于收银机的函数checkCashRegister()、传入售价为第一个参数(price)、支付金额为第二个参数(price)、收银机內的金额为第三个参数(cid)。", + "cid是包含货币面值的二维数组。", + "函数checkCashRegister()必须返回含有status键值和change键值的对象。", + "如果收银机內的金额少于应找回的零钱数,或者你无法返回确切的数目时,返回{status: \"INSUFFICIENT_FUNDS\", change: []}。", + "如果收银机內的金额等于应找回的零钱数,返回{status: \"CLOSED\", change: [...]},其中change键值是收银机內的金额。", + "否则,返回{status: \"OPEN\", change: [...]},其中change键值是应找回的零钱数,并且它的面值由高到低排序。", + "如果你遇到了问题,请点击帮助。", + "
货币单位面值
Penny$0.01 (PENNY)
Nickel$0.05 (NICKEL)
Dime$0.1 (DIME)
Quarter$0.25 (QUARTER)
Dollar$1 (DOLLAR)
Five Dollars$5 (FIVE)
Ten Dollars$10 (TEN)
Twenty Dollars$20 (TWENTY)
One-hundred Dollars$100 (ONE HUNDRED)
" ], "solutions": [ "var denom = [\n\t{ name: 'ONE HUNDRED', val: 100},\n\t{ name: 'TWENTY', val: 20},\n\t{ name: 'TEN', val: 10},\n\t{ name: 'FIVE', val: 5},\n\t{ name: 'ONE', val: 1},\n\t{ name: 'QUARTER', val: 0.25},\n\t{ name: 'DIME', val: 0.1},\n\t{ name: 'NICKEL', val: 0.05},\n\t{ name: 'PENNY', val: 0.01}\n];\n\nfunction checkCashRegister(price, cash, cid) {\n var output = {status: null, change: []};\n var change = cash - price;\n var register = cid.reduce(function(acc, curr) {\n acc.total += curr[1];\n acc[curr[0]] = curr[1];\n return acc;\n }, {total: 0});\n if(register.total === change) {\n output.status = 'CLOSED';\n output.change = cid;\n return output;\n }\n if(register.total < change) {\n output.status = 'INSUFFICIENT_FUNDS';\n return output;\n }\n var change_arr = denom.reduce(function(acc, curr) {\n var value = 0;\n while(register[curr.name] > 0 && change >= curr.val) {\n change -= curr.val;\n register[curr.name] -= curr.val;\n value += curr.val;\n change = Math.round(change * 100) / 100;\n }\n if(value > 0) {\n acc.push([ curr.name, value ]);\n }\n return acc;\n }, []);\n if(change_arr.length < 1 || change > 0) {\n output.status = 'INSUFFICIENT_FUNDS';\n return output;\n }\n output.status = 'OPEN';\n output.change = change_arr;\n return output;\n}" ], "tests": [ { - "text": "checkCashRegister(19.5, 20, [[\"PENNY\", 1.01], [\"NICKEL\", 2.05], [\"DIME\", 3.1], [\"QUARTER\", 4.25], [\"ONE\", 90], [\"FIVE\", 55], [\"TEN\", 20], [\"TWENTY\", 60], [\"ONE HUNDRED\", 100]]) should return an object.", - "testString": "assert.deepEqual(Object.prototype.toString.call(checkCashRegister(19.5, 20, [[\"PENNY\", 1.01], [\"NICKEL\", 2.05], [\"DIME\", 3.1], [\"QUARTER\", 4.25], [\"ONE\", 90], [\"FIVE\", 55], [\"TEN\", 20], [\"TWENTY\", 60], [\"ONE HUNDRED\", 100]])), '[object Object]', 'checkCashRegister(19.5, 20, [[\"PENNY\", 1.01], [\"NICKEL\", 2.05], [\"DIME\", 3.1], [\"QUARTER\", 4.25], [\"ONE\", 90], [\"FIVE\", 55], [\"TEN\", 20], [\"TWENTY\", 60], [\"ONE HUNDRED\", 100]]) should return an object.');" + "text": "checkCashRegister(19.5, 20, [[\"PENNY\", 1.01], [\"NICKEL\", 2.05], [\"DIME\", 3.1], [\"QUARTER\", 4.25], [\"ONE\", 90], [\"FIVE\", 55], [\"TEN\", 20], [\"TWENTY\", 60], [\"ONE HUNDRED\", 100]])应该返回一个对象。", + "testString": "assert.deepEqual(Object.prototype.toString.call(checkCashRegister(19.5, 20, [[\"PENNY\", 1.01], [\"NICKEL\", 2.05], [\"DIME\", 3.1], [\"QUARTER\", 4.25], [\"ONE\", 90], [\"FIVE\", 55], [\"TEN\", 20], [\"TWENTY\", 60], [\"ONE HUNDRED\", 100]])), '[object Object]', 'checkCashRegister(19.5, 20, [[\"PENNY\", 1.01], [\"NICKEL\", 2.05], [\"DIME\", 3.1], [\"QUARTER\", 4.25], [\"ONE\", 90], [\"FIVE\", 55], [\"TEN\", 20], [\"TWENTY\", 60], [\"ONE HUNDRED\", 100]])应该返回一个对象。');" }, { - "text": "checkCashRegister(19.5, 20, [[\"PENNY\", 1.01], [\"NICKEL\", 2.05], [\"DIME\", 3.1], [\"QUARTER\", 4.25], [\"ONE\", 90], [\"FIVE\", 55], [\"TEN\", 20], [\"TWENTY\", 60], [\"ONE HUNDRED\", 100]]) should return {status: \"OPEN\", change: [[\"QUARTER\", 0.5]]}.", - "testString": "assert.deepEqual(checkCashRegister(19.5, 20, [[\"PENNY\", 1.01], [\"NICKEL\", 2.05], [\"DIME\", 3.1], [\"QUARTER\", 4.25], [\"ONE\", 90], [\"FIVE\", 55], [\"TEN\", 20], [\"TWENTY\", 60], [\"ONE HUNDRED\", 100]]), {status: \"OPEN\", change: [[\"QUARTER\", 0.5]]}, 'checkCashRegister(19.5, 20, [[\"PENNY\", 1.01], [\"NICKEL\", 2.05], [\"DIME\", 3.1], [\"QUARTER\", 4.25], [\"ONE\", 90], [\"FIVE\", 55], [\"TEN\", 20], [\"TWENTY\", 60], [\"ONE HUNDRED\", 100]]) should return {status: \"OPEN\", change: [[\"QUARTER\", 0.5]]}.');" + "text": "checkCashRegister(19.5, 20, [[\"PENNY\", 1.01], [\"NICKEL\", 2.05], [\"DIME\", 3.1], [\"QUARTER\", 4.25], [\"ONE\", 90], [\"FIVE\", 55], [\"TEN\", 20], [\"TWENTY\", 60], [\"ONE HUNDRED\", 100]])应该返回{status: \"OPEN\", change: [[\"QUARTER\", 0.5]]}。", + "testString": "assert.deepEqual(checkCashRegister(19.5, 20, [[\"PENNY\", 1.01], [\"NICKEL\", 2.05], [\"DIME\", 3.1], [\"QUARTER\", 4.25], [\"ONE\", 90], [\"FIVE\", 55], [\"TEN\", 20], [\"TWENTY\", 60], [\"ONE HUNDRED\", 100]]), {status: \"OPEN\", change: [[\"QUARTER\", 0.5]]}, 'checkCashRegister(19.5, 20, [[\"PENNY\", 1.01], [\"NICKEL\", 2.05], [\"DIME\", 3.1], [\"QUARTER\", 4.25], [\"ONE\", 90], [\"FIVE\", 55], [\"TEN\", 20], [\"TWENTY\", 60], [\"ONE HUNDRED\", 100]])应该返回{status: \"OPEN\", change: [[\"QUARTER\", 0.5]]}。');" }, { - "text": "checkCashRegister(3.26, 100, [[\"PENNY\", 1.01], [\"NICKEL\", 2.05], [\"DIME\", 3.1], [\"QUARTER\", 4.25], [\"ONE\", 90], [\"FIVE\", 55], [\"TEN\", 20], [\"TWENTY\", 60], [\"ONE HUNDRED\", 100]]) should return {status: \"OPEN\", change: [[\"TWENTY\", 60], [\"TEN\", 20], [\"FIVE\", 15], [\"ONE\", 1], [\"QUARTER\", 0.5], [\"DIME\", 0.2], [\"PENNY\", 0.04]]}.", - "testString": "assert.deepEqual(checkCashRegister(3.26, 100, [[\"PENNY\", 1.01], [\"NICKEL\", 2.05], [\"DIME\", 3.1], [\"QUARTER\", 4.25], [\"ONE\", 90], [\"FIVE\", 55], [\"TEN\", 20], [\"TWENTY\", 60], [\"ONE HUNDRED\", 100]]), {status: \"OPEN\", change: [[\"TWENTY\", 60], [\"TEN\", 20], [\"FIVE\", 15], [\"ONE\", 1], [\"QUARTER\", 0.5], [\"DIME\", 0.2], [\"PENNY\", 0.04]]}, 'checkCashRegister(3.26, 100, [[\"PENNY\", 1.01], [\"NICKEL\", 2.05], [\"DIME\", 3.1], [\"QUARTER\", 4.25], [\"ONE\", 90], [\"FIVE\", 55], [\"TEN\", 20], [\"TWENTY\", 60], [\"ONE HUNDRED\", 100]]) should return {status: \"OPEN\", change: [[\"TWENTY\", 60], [\"TEN\", 20], [\"FIVE\", 15], [\"ONE\", 1], [\"QUARTER\", 0.5], [\"DIME\", 0.2], [\"PENNY\", 0.04]]}.');" + "text": "checkCashRegister(3.26, 100, [[\"PENNY\", 1.01], [\"NICKEL\", 2.05], [\"DIME\", 3.1], [\"QUARTER\", 4.25], [\"ONE\", 90], [\"FIVE\", 55], [\"TEN\", 20], [\"TWENTY\", 60], [\"ONE HUNDRED\", 100]])应该返回{status: \"OPEN\", change: [[\"TWENTY\", 60], [\"TEN\", 20], [\"FIVE\", 15], [\"ONE\", 1], [\"QUARTER\", 0.5], [\"DIME\", 0.2], [\"PENNY\", 0.04]]}。", + "testString": "assert.deepEqual(checkCashRegister(3.26, 100, [[\"PENNY\", 1.01], [\"NICKEL\", 2.05], [\"DIME\", 3.1], [\"QUARTER\", 4.25], [\"ONE\", 90], [\"FIVE\", 55], [\"TEN\", 20], [\"TWENTY\", 60], [\"ONE HUNDRED\", 100]]), {status: \"OPEN\", change: [[\"TWENTY\", 60], [\"TEN\", 20], [\"FIVE\", 15], [\"ONE\", 1], [\"QUARTER\", 0.5], [\"DIME\", 0.2], [\"PENNY\", 0.04]]}, 'checkCashRegister(3.26, 100, [[\"PENNY\", 1.01], [\"NICKEL\", 2.05], [\"DIME\", 3.1], [\"QUARTER\", 4.25], [\"ONE\", 90], [\"FIVE\", 55], [\"TEN\", 20], [\"TWENTY\", 60], [\"ONE HUNDRED\", 100]])应该返回{status: \"OPEN\", change: [[\"TWENTY\", 60], [\"TEN\", 20], [\"FIVE\", 15], [\"ONE\", 1], [\"QUARTER\", 0.5], [\"DIME\", 0.2], [\"PENNY\", 0.04]]}。');" }, { - "text": "checkCashRegister(19.5, 20, [[\"PENNY\", 0.01], [\"NICKEL\", 0], [\"DIME\", 0], [\"QUARTER\", 0], [\"ONE\", 0], [\"FIVE\", 0], [\"TEN\", 0], [\"TWENTY\", 0], [\"ONE HUNDRED\", 0]]) should return {status: \"INSUFFICIENT_FUNDS\", change: []}.", - "testString": "assert.deepEqual(checkCashRegister(19.5, 20, [[\"PENNY\", 0.01], [\"NICKEL\", 0], [\"DIME\", 0], [\"QUARTER\", 0], [\"ONE\", 0], [\"FIVE\", 0], [\"TEN\", 0], [\"TWENTY\", 0], [\"ONE HUNDRED\", 0]]), {status: \"INSUFFICIENT_FUNDS\", change: []}, 'checkCashRegister(19.5, 20, [[\"PENNY\", 0.01], [\"NICKEL\", 0], [\"DIME\", 0], [\"QUARTER\", 0], [\"ONE\", 0], [\"FIVE\", 0], [\"TEN\", 0], [\"TWENTY\", 0], [\"ONE HUNDRED\", 0]]) should return {status: \"INSUFFICIENT_FUNDS\", change: []}.');" + "text": "checkCashRegister(19.5, 20, [[\"PENNY\", 0.01], [\"NICKEL\", 0], [\"DIME\", 0], [\"QUARTER\", 0], [\"ONE\", 0], [\"FIVE\", 0], [\"TEN\", 0], [\"TWENTY\", 0], [\"ONE HUNDRED\", 0]])应该返回{status: \"INSUFFICIENT_FUNDS\", change: []}。", + "testString": "assert.deepEqual(checkCashRegister(19.5, 20, [[\"PENNY\", 0.01], [\"NICKEL\", 0], [\"DIME\", 0], [\"QUARTER\", 0], [\"ONE\", 0], [\"FIVE\", 0], [\"TEN\", 0], [\"TWENTY\", 0], [\"ONE HUNDRED\", 0]]), {status: \"INSUFFICIENT_FUNDS\", change: []}, 'checkCashRegister(19.5, 20, [[\"PENNY\", 0.01], [\"NICKEL\", 0], [\"DIME\", 0], [\"QUARTER\", 0], [\"ONE\", 0], [\"FIVE\", 0], [\"TEN\", 0], [\"TWENTY\", 0], [\"ONE HUNDRED\", 0]])应该返回{status: \"INSUFFICIENT_FUNDS\", change: []}。');" }, { - "text": "checkCashRegister(19.5, 20, [[\"PENNY\", 0.01], [\"NICKEL\", 0], [\"DIME\", 0], [\"QUARTER\", 0], [\"ONE\", 1], [\"FIVE\", 0], [\"TEN\", 0], [\"TWENTY\", 0], [\"ONE HUNDRED\", 0]]) should return {status: \"INSUFFICIENT_FUNDS\", change: []}.", - "testString": "assert.deepEqual(checkCashRegister(19.5, 20, [[\"PENNY\", 0.01], [\"NICKEL\", 0], [\"DIME\", 0], [\"QUARTER\", 0], [\"ONE\", 1], [\"FIVE\", 0], [\"TEN\", 0], [\"TWENTY\", 0], [\"ONE HUNDRED\", 0]]), {status: \"INSUFFICIENT_FUNDS\", change: []}, 'checkCashRegister(19.5, 20, [[\"PENNY\", 0.01], [\"NICKEL\", 0], [\"DIME\", 0], [\"QUARTER\", 0], [\"ONE\", 1], [\"FIVE\", 0], [\"TEN\", 0], [\"TWENTY\", 0], [\"ONE HUNDRED\", 0]]) should return {status: \"INSUFFICIENT_FUNDS\", change: []}.');" + "text": "checkCashRegister(19.5, 20, [[\"PENNY\", 0.01], [\"NICKEL\", 0], [\"DIME\", 0], [\"QUARTER\", 0], [\"ONE\", 1], [\"FIVE\", 0], [\"TEN\", 0], [\"TWENTY\", 0], [\"ONE HUNDRED\", 0]])应该返回{status: \"INSUFFICIENT_FUNDS\", change: []}。", + "testString": "assert.deepEqual(checkCashRegister(19.5, 20, [[\"PENNY\", 0.01], [\"NICKEL\", 0], [\"DIME\", 0], [\"QUARTER\", 0], [\"ONE\", 1], [\"FIVE\", 0], [\"TEN\", 0], [\"TWENTY\", 0], [\"ONE HUNDRED\", 0]]), {status: \"INSUFFICIENT_FUNDS\", change: []}, 'checkCashRegister(19.5, 20, [[\"PENNY\", 0.01], [\"NICKEL\", 0], [\"DIME\", 0], [\"QUARTER\", 0], [\"ONE\", 1], [\"FIVE\", 0], [\"TEN\", 0], [\"TWENTY\", 0], [\"ONE HUNDRED\", 0]])应该返回{status: \"INSUFFICIENT_FUNDS\", change: []}。');" }, { - "text": "checkCashRegister(19.5, 20, [[\"PENNY\", 0.5], [\"NICKEL\", 0], [\"DIME\", 0], [\"QUARTER\", 0], [\"ONE\", 0], [\"FIVE\", 0], [\"TEN\", 0], [\"TWENTY\", 0], [\"ONE HUNDRED\", 0]]) should return {status: \"CLOSED\", change: [[\"PENNY\", 0.5], [\"NICKEL\", 0], [\"DIME\", 0], [\"QUARTER\", 0], [\"ONE\", 0], [\"FIVE\", 0], [\"TEN\", 0], [\"TWENTY\", 0], [\"ONE HUNDRED\", 0]]}.", - "testString": "assert.deepEqual(checkCashRegister(19.5, 20, [[\"PENNY\", 0.5], [\"NICKEL\", 0], [\"DIME\", 0], [\"QUARTER\", 0], [\"ONE\", 0], [\"FIVE\", 0], [\"TEN\", 0], [\"TWENTY\", 0], [\"ONE HUNDRED\", 0]]), {status: \"CLOSED\", change: [[\"PENNY\", 0.5], [\"NICKEL\", 0], [\"DIME\", 0], [\"QUARTER\", 0], [\"ONE\", 0], [\"FIVE\", 0], [\"TEN\", 0], [\"TWENTY\", 0], [\"ONE HUNDRED\", 0]]}, 'checkCashRegister(19.5, 20, [[\"PENNY\", 0.5], [\"NICKEL\", 0], [\"DIME\", 0], [\"QUARTER\", 0], [\"ONE\", 0], [\"FIVE\", 0], [\"TEN\", 0], [\"TWENTY\", 0], [\"ONE HUNDRED\", 0]]) should return {status: \"CLOSED\", change: [[\"PENNY\", 0.5], [\"NICKEL\", 0], [\"DIME\", 0], [\"QUARTER\", 0], [\"ONE\", 0], [\"FIVE\", 0], [\"TEN\", 0], [\"TWENTY\", 0], [\"ONE HUNDRED\", 0]]}.');" + "text": "checkCashRegister(19.5, 20, [[\"PENNY\", 0.5], [\"NICKEL\", 0], [\"DIME\", 0], [\"QUARTER\", 0], [\"ONE\", 0], [\"FIVE\", 0], [\"TEN\", 0], [\"TWENTY\", 0], [\"ONE HUNDRED\", 0]])应该返回{status: \"CLOSED\", change: [[\"PENNY\", 0.5], [\"NICKEL\", 0], [\"DIME\", 0], [\"QUARTER\", 0], [\"ONE\", 0], [\"FIVE\", 0], [\"TEN\", 0], [\"TWENTY\", 0], [\"ONE HUNDRED\", 0]]}。", + "testString": "assert.deepEqual(checkCashRegister(19.5, 20, [[\"PENNY\", 0.5], [\"NICKEL\", 0], [\"DIME\", 0], [\"QUARTER\", 0], [\"ONE\", 0], [\"FIVE\", 0], [\"TEN\", 0], [\"TWENTY\", 0], [\"ONE HUNDRED\", 0]]), {status: \"CLOSED\", change: [[\"PENNY\", 0.5], [\"NICKEL\", 0], [\"DIME\", 0], [\"QUARTER\", 0], [\"ONE\", 0], [\"FIVE\", 0], [\"TEN\", 0], [\"TWENTY\", 0], [\"ONE HUNDRED\", 0]]}, 'checkCashRegister(19.5, 20, [[\"PENNY\", 0.5], [\"NICKEL\", 0], [\"DIME\", 0], [\"QUARTER\", 0], [\"ONE\", 0], [\"FIVE\", 0], [\"TEN\", 0], [\"TWENTY\", 0], [\"ONE HUNDRED\", 0]])应该返回{status: \"CLOSED\", change: [[\"PENNY\", 0.5], [\"NICKEL\", 0], [\"DIME\", 0], [\"QUARTER\", 0], [\"ONE\", 0], [\"FIVE\", 0], [\"TEN\", 0], [\"TWENTY\", 0], [\"ONE HUNDRED\", 0]]}。');" } ], "isRequired": true, From 39c96d4f370ef2dce5ff5e28bb2ed75a9cb99fc1 Mon Sep 17 00:00:00 2001 From: LynnLian Date: Wed, 1 Aug 2018 20:43:50 +0200 Subject: [PATCH 2/4] Cash Register - update for comment --- .../javascript-algorithms-and-data-structures-projects.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects.json b/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects.json index ab46cbc..669b48f 100644 --- a/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects.json +++ b/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects.json @@ -451,7 +451,7 @@ "cid是包含货币面值的二维数组。", "函数checkCashRegister()必须返回含有status键值和change键值的对象。", "如果收银机內的金额少于应找回的零钱数,或者你无法返回确切的数目时,返回{status: \"INSUFFICIENT_FUNDS\", change: []}。", - "如果收银机內的金额等于应找回的零钱数,返回{status: \"CLOSED\", change: [...]},其中change键值是收银机內的金额。", + "如果收银机內的金额等于应找回的零钱数,返回{status: \"CLOSED\", change: [...]},其中change键值是收银机內的金额。", "否则,返回{status: \"OPEN\", change: [...]},其中change键值是应找回的零钱数,并且它的面值由高到低排序。", "如果你遇到了问题,请点击帮助。", "
货币单位面值
Penny$0.01 (PENNY)
Nickel$0.05 (NICKEL)
Dime$0.1 (DIME)
Quarter$0.25 (QUARTER)
Dollar$1 (DOLLAR)
Five Dollars$5 (FIVE)
Ten Dollars$10 (TEN)
Twenty Dollars$20 (TWENTY)
One-hundred Dollars$100 (ONE HUNDRED)
" From 60aef745d5d450ad084fba7cc7a5a2056b78098f Mon Sep 17 00:00:00 2001 From: LynnLian Date: Wed, 1 Aug 2018 22:18:47 +0200 Subject: [PATCH 3/4] =?UTF-8?q?=E7=BF=BB=E8=AF=91.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 考虑json文件中没有翻译title,所以这里也保留 --- ...script-algorithms-and-data-structures-projects.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects.md b/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects.md index 6123a26..2de68da 100644 --- a/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects.md +++ b/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects.md @@ -1,8 +1,8 @@ -# Introduction to the JavaScript Algorithms and Data Structures Projects # +# Javascript 算法和数据项目简介 # -Time to put your new JavaScript skills to work! These challenges will be similar to the algorithm scripting challenges but more difficult. This will allow you to prove how much you have learned. +是时候用上你的Javascr技能了!接下来的挑战和算法脚本的挑战很相近,但是难度会更高。这可以证明你究竟学到了多少。 -In this section you will create the following small JavaScript programs: +在这一章,你将会使用Javascript创建以下项目: * Roman Numeral Converter @@ -12,6 +12,8 @@ In this section you will create the following small JavaScript programs: * Cash Register -Have fun and remember to use the Read-Search-Ask method if you get stuck. +好好享受。遇到问题时,记得先细读问题,然后上网搜索,最后才向其他人提问。 + +祝你好运! + -Good Luck! From 58cc837199b62f5057d7ad1af939f4dd921b71c2 Mon Sep 17 00:00:00 2001 From: LynnLian Date: Mon, 6 Aug 2018 20:15:40 +0200 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 JavaScript 拼写 - 根据 comment 加上缺失的翻译 --- .../javascript-algorithms-and-data-structures-projects.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects.md b/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects.md index 2de68da..cf6ae89 100644 --- a/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects.md +++ b/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects.md @@ -1,8 +1,8 @@ -# Javascript 算法和数据项目简介 # +# JavaScript 算法和数据结构项目简介 # -是时候用上你的Javascr技能了!接下来的挑战和算法脚本的挑战很相近,但是难度会更高。这可以证明你究竟学到了多少。 +是时候用上你新学到的 JavaScript 技能了!接下来的挑战和算法脚本的挑战很相近,但是难度会更高。这可以证明你究竟学到了多少。 -在这一章,你将会使用Javascript创建以下项目: +在这一章,你将会使用 JavaScript 创建以下项目: * Roman Numeral Converter