Translate algorithms#10
Conversation
S1ngS1ng
left a comment
There was a problem hiding this comment.
- 所有的 markdown 语法都要改成 HTML 语法才行
- 建议采用 JavaScript 的语法举例
- 题目的描述,特别是有多个参数的时候,建议分开描述。先解释传入的每个参数的意义,然后再细致地描述题目逻辑。可以参考我的翻译:
| "Create a function that takes two or more arrays and returns an array of the <dfn>symmetric difference</dfn> (<code>△</code> or <code>⊕</code>) of the provided arrays.", | ||
| "Given two sets (for example set <code>A = {1, 2, 3}</code> and set <code>B = {2, 3, 4}</code>), 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 (<code>A △ B = C = {1, 4}</code>). For every additional symmetric difference you take (say on a set <code>D = {2, 3}</code>), you should get the set with elements which are in either of the two the sets but not both (<code>C △ D = {1, 4} △ {2, 3} = {1, 2, 3, 4}</code>). The resulting array must contain only unique values (<em>no duplicates</em>).", | ||
| "Remember to use <a href='http://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck/19514' target='_blank'>Read-Search-Ask</a> if you get stuck. Try to pair program. Write your own code." | ||
| "知识提要:对称差 (Symmetric Difference),数学上,两个 <a href='https://baike.baidu.com/item/%E9%9B%86%E5%90%88/2908117' target='_blank'>集合</a> 的对称差是只属于其中一个集合,而不属于另一个集合的元素组成的集合,例如:集合 A = { 1, 2, 3} 和 B = { 2, 3, 4} 的对称差为 A △ B = C = {1,4},。 集合论中的这个运算相当于布尔逻辑中的异或运算。<a href='https://baike.baidu.com/item/%E5%AF%B9%E7%A7%B0%E5%B7%AE' target='_blank'>百科</a>。", |
There was a problem hiding this comment.
建议把 对称差 的链接放到前面。
知识提要:<a href='https://baike.baidu.com/item/%E5%AF%B9%E7%A7%B0%E5%B7%AE' target='_blank'>对称差</a>(Symmetric Difference)。
既然是 JavaScript 平台,建议用 [1, 2, 3] 来表示数组。下同
| "Given two sets (for example set <code>A = {1, 2, 3}</code> and set <code>B = {2, 3, 4}</code>), 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 (<code>A △ B = C = {1, 4}</code>). For every additional symmetric difference you take (say on a set <code>D = {2, 3}</code>), you should get the set with elements which are in either of the two the sets but not both (<code>C △ D = {1, 4} △ {2, 3} = {1, 2, 3, 4}</code>). The resulting array must contain only unique values (<em>no duplicates</em>).", | ||
| "Remember to use <a href='http://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck/19514' target='_blank'>Read-Search-Ask</a> if you get stuck. Try to pair program. Write your own code." | ||
| "知识提要:对称差 (Symmetric Difference),数学上,两个 <a href='https://baike.baidu.com/item/%E9%9B%86%E5%90%88/2908117' target='_blank'>集合</a> 的对称差是只属于其中一个集合,而不属于另一个集合的元素组成的集合,例如:集合 A = { 1, 2, 3} 和 B = { 2, 3, 4} 的对称差为 A △ B = C = {1,4},。 集合论中的这个运算相当于布尔逻辑中的异或运算。<a href='https://baike.baidu.com/item/%E5%AF%B9%E7%A7%B0%E5%B7%AE' target='_blank'>百科</a>。", | ||
| "创建一个函数sym,输入两个或两个以上的数组作为参数,然后返回值为 **对称差** 的数组", |
There was a problem hiding this comment.
然后返回值为 **对称差** 的数组 => 以数组的形式返回它们的对称差。
注意,这里用 markdown syntax 是不行的。如果要强调,也许要用 <em> 或者 <b> 这样的包裹起来
下同
| "知识提要:对称差 (Symmetric Difference),数学上,两个 <a href='https://baike.baidu.com/item/%E9%9B%86%E5%90%88/2908117' target='_blank'>集合</a> 的对称差是只属于其中一个集合,而不属于另一个集合的元素组成的集合,例如:集合 A = { 1, 2, 3} 和 B = { 2, 3, 4} 的对称差为 A △ B = C = {1,4},。 集合论中的这个运算相当于布尔逻辑中的异或运算。<a href='https://baike.baidu.com/item/%E5%AF%B9%E7%A7%B0%E5%B7%AE' target='_blank'>百科</a>。", | ||
| "创建一个函数sym,输入两个或两个以上的数组作为参数,然后返回值为 **对称差** 的数组", | ||
| "思路:设定两个数组 (例如:<code>A = {1, 2, 3}</code>,<code>B = {2, 3, 4}</code>,)作为参数传入,返回对称差数组(<code>A △ B = C = {1, 4}</code>),且数组元素具有唯一性(没有重复项)。", | ||
| "如果你遇到了困难,请点击 <a href='http://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck/19514' target='_blank'>帮助</a>。请尽量编写属于你自己的代码。尝试一下 **结对编程** 会有意料不到的惊喜哦。", |
There was a problem hiding this comment.
| "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 <code>arr1</code>). 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 <a href='http://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck/19514' target='_blank'>Read-Search-Ask</a> if you get stuck. Try to pair program. Write your own code." | ||
| "", | ||
| "比较和更新存储在 <a href='https://baike.baidu.com/item/%E4%BA%8C%E7%BB%B4%E6%95%B0%E7%BB%84' target='_blank'>2D数组 </a>中的库存,并将其与新交付的第二个2D数组进行比较。更新当前的库存项数量(arr1)。如果找不到项目,请将新项目和数量添加到库存数组中。返回的库存数组应该按照项目的字母顺序排列。", |
There was a problem hiding this comment.
2D数组 => 二维数组
建议更新题目描述,见 review comments
|
@BigFaceMaster 另外,你添加了 |
S1ngS1ng
left a comment
There was a problem hiding this comment.
空格改一下。之前的 comments 也看一下,你还都没改。先别添加新的翻译内容了
| { | ||
| "text": "<code>permAlone(\"aab\")</code> should return 2.", | ||
| "testString": "assert.strictEqual(permAlone('aab'), 2,'<code>permAlone(\"aab\")</code> should return 2.');" | ||
| "text": "<code>permAlone(\"aab\")</code> 应该返回 2 。", |
There was a problem hiding this comment.
半角字符与全角标点之间不应该添加空格。见群内讨论
所以这里是 应该返回 2。
下同
| "Below we'll take their corresponding indices and add them.", | ||
| "7 + 13 = 20 → Indices 0 + 3 = 3<br>9 + 11 = 20 → Indices 1 + 2 = 3<br>3 + 3 = 6 → Return <code>6</code>", | ||
| "Remember to use <a href='http://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck/19514'target='_blank'>Read-Search-Ask</a> if you get stuck. Try to pair program. Write your own code." | ||
| "如果你遇到了困难,请点击 <a href='http://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck/19514'target='_blank'> 帮助 </a>。你可以找人 “结对编程”,但不要因此放弃思考。", |
There was a problem hiding this comment.
见群内讨论。行内元素是否加空格取决于里面的内容。
中文引号两边也是不需要加空格的
如果你遇到了困难,请点击<a href='http://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck/19514'target='_blank'>帮助</a>。你可以找人“结对编程”,但不要因此放弃思考。
| "Create a function that takes two or more arrays and returns an array of the <dfn>symmetric difference</dfn> (<code>△</code> or <code>⊕</code>) of the provided arrays.", | ||
| "Given two sets (for example set <code>A = {1, 2, 3}</code> and set <code>B = {2, 3, 4}</code>), 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 (<code>A △ B = C = {1, 4}</code>). For every additional symmetric difference you take (say on a set <code>D = {2, 3}</code>), you should get the set with elements which are in either of the two the sets but not both (<code>C △ D = {1, 4} △ {2, 3} = {1, 2, 3, 4}</code>). The resulting array must contain only unique values (<em>no duplicates</em>).", | ||
| "Remember to use <a href='http://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck/19514' target='_blank'>Read-Search-Ask</a> if you get stuck. Try to pair program. Write your own code." | ||
| "知识提要:对称差 (Symmetric Difference),数学上,两个 <a href='https://baike.baidu.com/item/%E9%9B%86%E5%90%88/2908117'target='_blank'> 集合 </a> 的对称差是只属于其中一个集合,而不属于另一个集合的元素组成的集合,例如:集合 A = { 1, 2, 3} 和 B = { 2, 3, 4} 的对称差为 A △ B = C = {1,4},。 集合论中的这个运算相当于布尔逻辑中的异或运算。<a href='https://baike.baidu.com/item/%E5%AF%B9%E7%A7%B0%E5%B7%AE'target='_blank'> 百科 </a>。", |
There was a problem hiding this comment.
Symmetric Difference => 对称差分
There was a problem hiding this comment.
There was a problem hiding this comment.
@BigFaceMaster 之前的 comments 你还没有改,点开 Show outdated 看下。
比如数组的表示方式,markdown syntax 要删掉,以及<a>标签里面其实不需要加空格。
麻烦你更新下哈。内容方面应该没有问题了
|
已经根据建议 ,更改并优化。 |
| "Create a function that takes two or more arrays and returns an array of the <dfn>symmetric difference</dfn> (<code>△</code> or <code>⊕</code>) of the provided arrays.", | ||
| "Given two sets (for example set <code>A = {1, 2, 3}</code> and set <code>B = {2, 3, 4}</code>), 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 (<code>A △ B = C = {1, 4}</code>). For every additional symmetric difference you take (say on a set <code>D = {2, 3}</code>), you should get the set with elements which are in either of the two the sets but not both (<code>C △ D = {1, 4} △ {2, 3} = {1, 2, 3, 4}</code>). The resulting array must contain only unique values (<em>no duplicates</em>).", | ||
| "Remember to use <a href='http://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck/19514' target='_blank'>Read-Search-Ask</a> if you get stuck. Try to pair program. Write your own code." | ||
| "知识提要:<a href='https://baike.baidu.com/item/%E5%AF%B9%E7%A7%B0%E5%B7%AE'target='_blank'>对称差 (Symmetric Difference)</a>,数学上,两个 <a href='https://baike.baidu.com/item/%E9%9B%86%E5%90%88/2908117'target='_blank'>集合</a> 的对称差分是只属于其中一个集合,而不属于另一个集合的元素组成的集合,例如:集合<code>let A = [ 1, 2, 3]</code>和<code>let B = [ 2, 3, 4]</code>的对称差分为<code>A △ B = C = [ 1, 4]</code>,。 集合论中的这个运算相当于布尔逻辑中的异或运算。", |
| "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 <code>arr1</code>). 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 <a href='http://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck/19514' target='_blank'>Read-Search-Ask</a> if you get stuck. Try to pair program. Write your own code." | ||
| "", | ||
| "比较和更新存储在<a href='https://baike.baidu.com/item/%E4%BA%8C%E7%BB%B4%E6%95%B0%E7%BB%84'target='_blank'>二维数组</a>中的库存,并将其与新交付的第二个二维数组进行比较。更新当前的库存项数量(arr1)。如果找不到项目,请将新项目和数量添加到库存数组中。返回的库存数组应该按照项目的字母顺序排列。", |
There was a problem hiding this comment.
@BigFaceMaster 内容上没啥大问题。但其他部分,不翻译的/不需要改的部分就不要改,保持和原文一样就行,否则后续很难做 diff。
格式问题记得参考 style-guide
| "Create a function that takes two or more arrays and returns an array of the <dfn>symmetric difference</dfn> (<code>△</code> or <code>⊕</code>) of the provided arrays.", | ||
| "Given two sets (for example set <code>A = {1, 2, 3}</code> and set <code>B = {2, 3, 4}</code>), 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 (<code>A △ B = C = {1, 4}</code>). For every additional symmetric difference you take (say on a set <code>D = {2, 3}</code>), you should get the set with elements which are in either of the two the sets but not both (<code>C △ D = {1, 4} △ {2, 3} = {1, 2, 3, 4}</code>). The resulting array must contain only unique values (<em>no duplicates</em>).", | ||
| "Remember to use <a href='http://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck/19514' target='_blank'>Read-Search-Ask</a> if you get stuck. Try to pair program. Write your own code." | ||
| "知识提要:<a href='https://baike.baidu.com/item/%E5%AF%B9%E7%A7%B0%E5%B7%AE'target='_blank'>对称差 (Symmetric Difference)</a>,数学上,两个 <a href='https://baike.baidu.com/item/%E9%9B%86%E5%90%88/2908117'target='_blank'>集合</a> 的对称差分是只属于其中一个集合,而不属于另一个集合的元素组成的集合,例如:集合<code>let A = [ 1, 2, 3]</code>和<code>let B = [ 2, 3, 4]</code>的对称差分为<code>A △ B = C = [ 1, 4]</code>,。 集合论中的这个运算相当于布尔逻辑中的异或运算。", |
There was a problem hiding this comment.
两个 <a href='https://baike.baidu.com/item/%E9%9B%86%E5%90%88/2908117'target='_blank'>集合</a> 的对称差分是只属于其中一个集合,
由于 <a> 里面和外面都是全角,因此 <a> 两边不需要加空格。
最后哪个 </code> 之后多了一个半角逗号。
| "Remember to use <a href='http://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck/19514' target='_blank'>Read-Search-Ask</a> if you get stuck. Try to pair program. Write your own code." | ||
| "知识提要:<a href='https://baike.baidu.com/item/%E5%AF%B9%E7%A7%B0%E5%B7%AE'target='_blank'>对称差 (Symmetric Difference)</a>,数学上,两个 <a href='https://baike.baidu.com/item/%E9%9B%86%E5%90%88/2908117'target='_blank'>集合</a> 的对称差分是只属于其中一个集合,而不属于另一个集合的元素组成的集合,例如:集合<code>let A = [ 1, 2, 3]</code>和<code>let B = [ 2, 3, 4]</code>的对称差分为<code>A △ B = C = [ 1, 4]</code>,。 集合论中的这个运算相当于布尔逻辑中的异或运算。", | ||
| "创建一个函数 sym,输入两个或两个以上的数组作为参数,然后返回值为<em>对称差分</em>的数组", | ||
| "思路:设定两个数组 (例如:<code>let A = [1, 2, 3]</code>,<code>let B = [2, 3, 4]</code>,)作为参数传入,返回对称差分数组(<code>A △ B = C = [1, 4]</code>),且数组元素具有唯一性(没有重复项)。", |
There was a problem hiding this comment.
第一个括号里面,) 之前不应该加逗号
且数组元素具有唯一性(没有重复项)。 =>
且数组中没有重复项。
| "知识提要:<a href='https://baike.baidu.com/item/%E5%AF%B9%E7%A7%B0%E5%B7%AE'target='_blank'>对称差 (Symmetric Difference)</a>,数学上,两个 <a href='https://baike.baidu.com/item/%E9%9B%86%E5%90%88/2908117'target='_blank'>集合</a> 的对称差分是只属于其中一个集合,而不属于另一个集合的元素组成的集合,例如:集合<code>let A = [ 1, 2, 3]</code>和<code>let B = [ 2, 3, 4]</code>的对称差分为<code>A △ B = C = [ 1, 4]</code>,。 集合论中的这个运算相当于布尔逻辑中的异或运算。", | ||
| "创建一个函数 sym,输入两个或两个以上的数组作为参数,然后返回值为<em>对称差分</em>的数组", | ||
| "思路:设定两个数组 (例如:<code>let A = [1, 2, 3]</code>,<code>let B = [2, 3, 4]</code>,)作为参数传入,返回对称差分数组(<code>A △ B = C = [1, 4]</code>),且数组元素具有唯一性(没有重复项)。", | ||
| "如果你遇到了困难,请点击 <a href='http://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck/19514'target='_blank'>帮助</a>。你可以找人“结对编程”,但不要因此放弃思考。", |
| "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 <code>arr1</code>). 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 <a href='http://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck/19514' target='_blank'>Read-Search-Ask</a> if you get stuck. Try to pair program. Write your own code." | ||
| "创建一个<a href='https://baike.baidu.com/item/%E4%BA%8C%E7%BB%B4%E6%95%B0%E7%BB%84'target='_blank'>二维数组</a>,比较并更新存储在<code>二维数组</code>中的”库存“元素,然后并将其与新产生的第二个二维数组进行对比,更新当前的”库存“项的数量(<code>arr1</code>),如果找不到这个对比对象,那么将新的对象和数量添加到“库存”数组中。注意:返回的“库存”数组应该是按照数组元素的首字母顺序排序", |
| "For example, <code>aab</code> should return 2 because it has 6 total permutations (<code>aab</code>, <code>aab</code>, <code>aba</code>, <code>aba</code>, <code>baa</code>, <code>baa</code>), but only 2 of them (<code>aba</code> and <code>aba</code>) don't have the same letter (in this case <code>a</code>) repeating.", | ||
| "Remember to use <a href='http://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck/19514' target='_blank'>Read-Search-Ask</a> if you get stuck. Try to pair program. Write your own code." | ||
| "把一个字符串中的字符重新排列生成新的字符串,返回新生成的字符串里没有连续重复字符的字符串个数。连续重复只以单个字符为准。", | ||
| "例如:<code>aab</code>应该返回 2, 因为它总共有 6 种排列方式: <code>aab</code>, <code>aab</code>, <code>aba</code>, <code>aba</code>, <code>baa</code>, <code>baa</code>,但是其中只有 2 个没有连续重复的字符( 字符 a 是本例中的重复字符 ):<code>aba</code>,<code>aba</code>", |
| "Remember to use <a href='http://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck/19514' target='_blank'>Read-Search-Ask</a> if you get stuck. Try to pair program. Write your own code." | ||
| "把一个字符串中的字符重新排列生成新的字符串,返回新生成的字符串里没有连续重复字符的字符串个数。连续重复只以单个字符为准。", | ||
| "例如:<code>aab</code>应该返回 2, 因为它总共有 6 种排列方式: <code>aab</code>, <code>aab</code>, <code>aba</code>, <code>aba</code>, <code>baa</code>, <code>baa</code>,但是其中只有 2 个没有连续重复的字符( 字符 a 是本例中的重复字符 ):<code>aba</code>,<code>aba</code>", | ||
| "如果你遇到了困难,请点击 <a href='http://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck/19514'target='_blank'> 帮助 </a>。你可以找人” 结对编程 “,但不要因此放弃思考。" |
| ], | ||
| "solutions": [ | ||
| "function permAlone(str) {\n return permutor(str).filter(function(perm) {\n return !perm.match(/(.)\\1/g);\n }).length;\n}\n\nfunction permutor(str) {\n // http://staff.roguecc.edu/JMiller/JavaScript/permute.html\n //permArr: Global array which holds the list of permutations\n //usedChars: Global utility array which holds a list of \"currently-in-use\" characters\n var permArr = [], usedChars = [];\n function permute(input) {\n //convert input into a char array (one element for each character)\n var i, ch, chars = input.split(\"\");\n for (i = 0; i < chars.length; i++) {\n //get and remove character at index \"i\" from char array\n ch = chars.splice(i, 1);\n //add removed character to the end of used characters\n usedChars.push(ch);\n //when there are no more characters left in char array to add, add used chars to list of permutations\n if (chars.length === 0) permArr[permArr.length] = usedChars.join(\"\");\n //send characters (minus the removed one from above) from char array to be permuted\n permute(chars.join(\"\"));\n //add removed character back into char array in original position\n chars.splice(i, 0, ch);\n //remove the last character used off the end of used characters array\n usedChars.pop();\n }\n }\n permute(str);\n return permArr;\n}\n\npermAlone('aab');\n" | ||
| "function permAlone(str) {\n return permutor(str).filter(function(perm) {\n return !perm.match(/(.)\\1/g);\n }).length;\n}\n\nfunction permutor(str) {\n // http://staff.roguecc.edu/JMiller/JavaScript/permute.html\n //permArr: 全局数组:包含排列的列表 \ n //usedChars: 全局实用数组,其中一个列表包含 \"currently-in-use\"字符 var permArr = [], usedChars = [];\n function permute(input) {\n // 将输入参数转换成一个字符串数组 (每个字符都有一个元素)\n var i, ch, chars = input.split(\"\");\n for (i = 0; i < chars.length; i++) {\n // 从字符数组中获取并删除索引为\"i\"的字符 \n ch = chars.splice(i, 1);\n // 将删除的字符增加的使用字符的末尾 \n usedChars.push(ch);\n // 当char数组中没有其他字符添加时,添加使用的chars列表来排列排列 \n if (chars.length === 0) permArr[permArr.length] = usedChars.join(\"\");\n // 从char数组发送字符(减去上面删除的字符)进行置换 \n permute(chars.join(\"\"));\n // 将删除的数组添加回char数组中的原位置 \n chars.splice(i, 0, ch);\n //删除使用过的字符数组末尾使用的最后一个字符 \n usedChars.pop();\n }\n }\n permute(str);\n return permArr;\n}\n\npermAlone('aab');\n" |
There was a problem hiding this comment.
这个 solutions 是不需要翻译的。 @huluoyang 确认下?我记得这个只是用来执行判断的
| "contents": [ | ||
| "function permAlone(str) {", | ||
| " return str;", | ||
| "return str;", |
There was a problem hiding this comment.
这里的缩进不要移除,这个是用来在编辑器中显示代码的,去掉之后缩进就没了。
| "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);", |
There was a problem hiding this comment.
这里改了应该没事儿,但最好不要动,否则后续更新的时候会影响 diff 的判断
|
@BigFaceMaster 好 👍 把前面 comment 里提到的改下就好啦,没别的问题 |
… translate) Merge Request: functional-programming.json complete Created By: @黄雨纯 Accepted By: @黄雨纯 URL: https://freecodecamp.coding.net/p/challenges/git/merge/10

翻译章节
《面试前期准备——算法》
变更文件
algorithms.json
algorithms.md
翻译进度
45%
0%