-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
函数式编程 23/23 #50
base: translate
Are you sure you want to change the base?
函数式编程 23/23 #50
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 注意破折号的使用
——
。参考 style-guide - 意思翻译的基本没错,建议翻译后读一下,考虑前后文的连接是否自然。
- 多一些意译,少一些直译
"2) Pure functions - the same input always gives the same output", | ||
"3) Functions with limited side effects - any changes, or mutations, to the state of the program outside the function are carefully controlled", | ||
"函数式编程:", | ||
"1)功能独立 — 不依赖于程序的状态,其中包括可能发生变化的全局变量;", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议:不依赖于程序的状态(比如可能发生变化的全局变量);
"函数式编程:", | ||
"1)功能独立 — 不依赖于程序的状态,其中包括可能发生变化的全局变量;", | ||
"2)纯函数 - 同一个输入永远能得到同一个输出;", | ||
"3)有限的副作用 - 任何在函数外部更改或状态变化都严格地被控制。", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
尽量少用被动语态。
建议:可以严格地限制函数外部对状态的更改导致的状态变化。
"<hr>", | ||
"The members of freeCodeCamp happen to love tea.", | ||
"In the code editor, the <code>prepareTea</code> and <code>getTea</code> functions are already defined for you. Call the <code>getTea</code> function to get 40 cups of tea for the team, and store them in the <code>tea4TeamFCC</code> variable." | ||
"freeCodeCamp 成员在 love tea 的故事。", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个 love tea
是可以翻译的,不是某个组织,或有其他含义
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我感觉是个奶茶店的名字。。。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rainpure
原文是 The members of freeCodeCamp happen to love tea.
,其中 happen to
的意思是“恰好”、“碰巧”。因此,这个 love tea
也不应该是地名。
习惯上,如果这里的 love tea
真的是地名,那原文一定会写成 Love Tea
。而且前面的介词也不会用 to
,而是 at
。
(不过我觉得这个 “恰好” 或 “碰巧” 可以不用特别地翻译出来,反正对做题没影响,这里只是与做题的人分享个刚编的故事而已= =)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
啊,这里我也看到了感觉是有些微妙。
"text": "The <code>tea4TeamFCC</code> variable should hold cups of green tea.", | ||
"testString": "assert(tea4TeamFCC[0] === 'greenTea', 'The <code>tea4TeamFCC</code> variable should hold cups of green tea.');" | ||
"text": "<code>tea4TeamFCC</code>变量里应有绿茶。", | ||
"testString": "assert(tea4TeamFCC[0] === 'greenTea', '<code>tea4TeamFCC</code>变量里应有绿茶。');" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的“绿茶”建议保留原文 greenTea
"FCC 团队需求有变更,现在想要两种茶:绿茶和红茶。事实证明,用户需求变更是很常见的。", | ||
"基于以上信息,我们需要重构上一节挑战中的<code>getTea</code>函数来处理多种茶的请求。我们可以修改<code>getTea</code>接受一个函数作为参数,使它能够修改茶的类型。这让<code>getTea</code>更灵活,也使需求变更时为程序员提供更多控制权。", | ||
"首先,我们将介绍一些术语:", | ||
"<code>Callbacks</code>是被传递到另一个函数中调用的函数。你可能已经在其他函数中看过他们的传递,例如在<code>filter</code>中,回调函数告诉 JavaScript 以什么规则过滤数组。", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你可能已经在其他函数中看过他们的传递
=> 你应该已经在其他函数中看过这个写法
"最后一个挑战是更接近函数式编程原则的挑战,但是仍然缺少一些东西。", | ||
"虽然我们没有改变全局变量值,但在没有全局变量<code>fixedValue</code>情况下,<code>incrementer</code>函数将不起作用。", | ||
"函数式编程的另一个原则是:总是显式声明依赖关系。如果函数依赖于一个变量或对象,那么将该变量或对象作为参数直接传递到函数中。", | ||
"这个原则带来几个好的影响。让函数更容易测试,确切知道它需要什么输入,并且它不依赖于程序中的任何其他内容。", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个原则带来几个好的影响。让函数更容易测试,确切知道它需要什么输入,并且它不依赖于程序中的任何其他内容。
=>
这样做会有很多好处,其中一点是让函数更容易测试,因为你确切地知道参数是什么,并且这个参数也不依赖于程序中的任何其他内容。
注意,consequence
是结果的意思。
"虽然我们没有改变全局变量值,但在没有全局变量<code>fixedValue</code>情况下,<code>incrementer</code>函数将不起作用。", | ||
"函数式编程的另一个原则是:总是显式声明依赖关系。如果函数依赖于一个变量或对象,那么将该变量或对象作为参数直接传递到函数中。", | ||
"这个原则带来几个好的影响。让函数更容易测试,确切知道它需要什么输入,并且它不依赖于程序中的任何其他内容。", | ||
"可以让你更加自信地更改,删除或添加新代码。你会知道什么是可以或不可以改变的,你能看出哪里有潜在的陷阱。", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
其次,这样做可以让你……
你会知道什么是可以或不可以改变的,你能看出哪里有潜在的陷阱。
=>
因为你很清楚哪些是可以改的,哪些是不可以改的,这样你就知道哪里可能会有潜在的陷阱。
"目前为止,我们已经学会了使用纯函数来避免程序中的副作用。此外,我们已经看到函数的值仅取决于其输入参数。", | ||
"这仅仅是个开始。顾名思义,函数式编程以函数理论为中心。", | ||
"能够将它们作为参数传递给其他函数,和从另一个函数返回一个函数是有意义的。函数在 JavaScript 中被视为<code>First Class Objects</code>,它们可以像任何其他对象一样使用。它们可以保存在变量中,存储在对象中,也可以作为函数参数传递。", | ||
"让我们从一些简单的数组函数开始,这些函数是数组对象原型上的方法。在本练习中,我们将看到<code>Array.prototype.map()</code>或者更简单的<code>map</code>。", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的 or more simply <code>map</code>
与前文的 <code>Array.prototype.map()</code>
是一回事儿。
建议:在本练习中,我们来了解下数组的<code>map</code>方法(即<code>Array.prototype.map()</code>)。
"这仅仅是个开始。顾名思义,函数式编程以函数理论为中心。", | ||
"能够将它们作为参数传递给其他函数,和从另一个函数返回一个函数是有意义的。函数在 JavaScript 中被视为<code>First Class Objects</code>,它们可以像任何其他对象一样使用。它们可以保存在变量中,存储在对象中,也可以作为函数参数传递。", | ||
"让我们从一些简单的数组函数开始,这些函数是数组对象原型上的方法。在本练习中,我们将看到<code>Array.prototype.map()</code>或者更简单的<code>map</code>。", | ||
"请记住,<code>map</code>方法是迭代数组中每一项的方法。在对每个元素应用回调函数后,它会创建一个新数组(不改变原来的数组)。", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<code>map</code>方法是迭代数组中每一项的方法。
=>
<code>map</code>方法是迭代数组中每一项的方式之一。
"<hr>", | ||
"The <code>watchList</code> array holds objects with information on several movies. Use <code>map</code> to pull the title and rating from <code>watchList</code> and save the new array in the <code>rating</code> variable. The code in the editor currently uses a <code>for</code> loop to do this, replace the loop functionality with your <code>map</code> expression." | ||
"<code>watchList</code>数组保存了包含一些电影信息的对象。使用<code>map</code>从<code>watchList</code>中提取标题和评分,并将新数组保存在<code>rating</code>变量里。目前编辑器中的代码是使用<code>for</code>循环实现,使用<code>map</code>表达式替换循环功能。" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
使用<code>map</code>从<code>watchList</code>中提取标题(<code>title</code>)和评分(<code>rating</code>),
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+@wudifeixue for review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
修改一下吧。注意,翻译之后至少要自己通读一遍
@@ -1088,8 +1089,8 @@ | |||
"testString": "assert(code.match(/\\.reduce/g), 'Your code should use the <code>reduce</code> method.');" | |||
}, | |||
{ | |||
"text": "The <code>averageRating</code> should equal 8.675.", | |||
"testString": "assert(averageRating == 8.675, 'The <code>averageRating</code> should equal 8.675.');" | |||
"text": "The <code>averageRating</code>应等于8.675.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
数字前的空格是要加的。。<code>
不加是比较特殊的情况,因为 render 效果不好。但这个与全角/半角之间要加空格并不矛盾
"In other words, <code>map</code> is a pure function, and its output depends solely on its inputs. Plus, it takes another function as its argument.", | ||
"It would teach us a lot about <code>map</code> to try to implement a version of it that behaves exactly like the <code>Array.prototype.map()</code> with a <code>for</code> loop or <code>Array.prototype.forEach()</code>.", | ||
"Note: A pure function is allowed to alter local variables defined within its scope, although, it's preferable to avoid that as well.", | ||
"你前面用的<code>map</code>方法(即<code>Array.prototype.map()</code>,<code>map</code>方法返回一个与调用它的数组长度相同的数组。只要它的回调函数不改变原始数组,它就不会改变原始数组。", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你前面用的<code>map</code>方法(即<code>Array.prototype.map()</code>,<code>map</code>方法返回一个与调用它的数组长度相同的数组。
内容重复,而且少了个全角括号 )
我们之前使用的<code>map</code>方法(即<code>Array.prototype.map()</code>)返回一个与调用它的数组长度相同的数组。
"It would teach us a lot about <code>map</code> to try to implement a version of it that behaves exactly like the <code>Array.prototype.map()</code> with a <code>for</code> loop or <code>Array.prototype.forEach()</code>.", | ||
"Note: A pure function is allowed to alter local variables defined within its scope, although, it's preferable to avoid that as well.", | ||
"你前面用的<code>map</code>方法(即<code>Array.prototype.map()</code>,<code>map</code>方法返回一个与调用它的数组长度相同的数组。只要它的回调函数不改变原始数组,它就不会改变原始数组。", | ||
"换一句话说,<code>map</code>是一个纯函数,它的输出完全取决于它的输入;另外,它需要另一个函数作为它的参数。", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Note: A pure function is allowed to alter local variables defined within its scope, although, it's preferable to avoid that as well.", | ||
"你前面用的<code>map</code>方法(即<code>Array.prototype.map()</code>,<code>map</code>方法返回一个与调用它的数组长度相同的数组。只要它的回调函数不改变原始数组,它就不会改变原始数组。", | ||
"换一句话说,<code>map</code>是一个纯函数,它的输出完全取决于它的输入;另外,它需要另一个函数作为它的参数。", | ||
"它会教会我们更多关于用<code>map</code>去实现一个与<code>for</code>或<code>Array.prototype.forEach()</code>行为完全一样的<code>Array.prototype.map()</code>版本。", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
它会教会我们更多关于用<code>map</code>去实现一个与<code>for</code>或<code>Array.prototype.forEach()</code>行为完全一样的<code>Array.prototype.map()</code>版本。
=>
现在我们来用<code>for</code>或<code>Array.prototype.forEach()</code>自己实现一下<code>map</code>方法,这样做可以加深我们对它的理解。
或
为了加深对<code>map</code>方法的理解,现在我们来用<code>for</code>或<code>Array.prototype.forEach()</code>自己实现一下这个方法。
It
是形式主语,一般不翻译成 它
,要补全
"你前面用的<code>map</code>方法(即<code>Array.prototype.map()</code>,<code>map</code>方法返回一个与调用它的数组长度相同的数组。只要它的回调函数不改变原始数组,它就不会改变原始数组。", | ||
"换一句话说,<code>map</code>是一个纯函数,它的输出完全取决于它的输入;另外,它需要另一个函数作为它的参数。", | ||
"它会教会我们更多关于用<code>map</code>去实现一个与<code>for</code>或<code>Array.prototype.forEach()</code>行为完全一样的<code>Array.prototype.map()</code>版本。", | ||
"注意:纯函数可以改变其作用域内定义的局部变量,最好也尽管避免使用。", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最好也尽管避免使用。
=>
但我们应避免这样做。
或
但我们最好不要这样做。
although
的转折语气要翻译出来
"Another useful array function is <code>Array.prototype.filter()</code>, or simply <code>filter()</code>. The <code>filter</code> method returns a new array which is at most as long as the original array, but usually has fewer items.", | ||
"<code>Filter</code> doesn't alter the original array, just like <code>map</code>. It takes a callback function that applies the logic inside the callback on each element of the array. If an element returns true based on the criteria in the callback function, then it is included in the new array.", | ||
"另一个有用的数组函数是<code>filter()</code>(即<code>Array.prototype.filter()</code>)。<code>filter</code>方法通常返回一个比原始数组短的新数组,最多与原始数组一样长。", | ||
"和<code>map</code>一样,<code>Filter</code>不会改变原始数组,它需要一个回调函数,它将回调内的逻辑应用于数组的每个元素。新数组中包含根据回调函数中的条件返回 true 的元素。", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
takes
: 接收
"<hr>", | ||
"The variable <code>watchList</code> holds an array of objects with information on several movies. Use a combination of <code>filter</code> and <code>map</code> to return a new array of objects with only <code>title</code> and <code>rating</code> keys, but where <code>imdbRating</code> is greater than or equal to 8.0. Note that the rating values are saved as strings in the object and you may want to convert them into numbers to perform mathematical operations on them." | ||
"<code>watchList</code>是包含一些电影信息的对象。结合使用<code>filter</code>和<code>map</code>返回一个只包含<code>title</code>和<code>rating</code>关键字的新数组,但是<code>imdbRating</code>需要大于或等于 8.0。请注意,评级值在对象中保存为字符串,你可能需要将它转换成数字来执行运算。" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
关键字
=> 属性
], | ||
"tests": [ | ||
{ | ||
"text": "The <code>watchList</code> variable should not change.", | ||
"testString": "assert(watchList[0].Title === \"Inception\" && watchList[4].Director == \"James Cameron\", 'The <code>watchList</code> variable should not change.');" | ||
"text": "<code>watchList</code>不能被改变。", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不能被改变。
=> 应保持不变。
下同
@@ -807,19 +807,20 @@ | |||
"id": "587d7b8f367417b2b2512b64", | |||
"title": "Implement the filter Method on a Prototype", | |||
"description": [ | |||
"It would teach us a lot about the <code>filter</code> method if we try to implement a version of it that behaves exactly like <code>Array.prototype.filter()</code>. It can use either a <code>for</code> loop or <code>Array.prototype.forEach()</code>.", | |||
"Note: A pure function is allowed to alter local variables defined within its scope, although, it's preferable to avoid that as well.", | |||
"如果我们尝试实现与<code>Array.prototype.filter()</code>完全相同的功能,我们将会学到很多关于<code>filter</code>方法的内容。", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
"Note: A pure function is allowed to alter local variables defined within its scope, although, it's preferable to avoid that as well.", | ||
"如果我们尝试实现与<code>Array.prototype.filter()</code>完全相同的功能,我们将会学到很多关于<code>filter</code>方法的内容。", | ||
"可以使用<code>for</code>循环或<code>Array.prototype.forEach()</code>。", | ||
"请注意:纯函数可以改变其作用域内定义的局部变量,最好也尽管避免使用。", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
我正在看,目前看了前200行问题不大,接着往后继续 |
翻译章节
《函数式编程》
变更文件
翻译进度