From 01b0e12ba27b5069248fd09235e9a7143915ee30 Mon Sep 17 00:00:00 2001 From: Irvin Date: Wed, 16 Feb 2022 02:02:49 +0800 Subject: remove `notranslate` class in zh-CN --- .../global_objects/array/reduceright/index.html | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'files/zh-cn/web/javascript/reference/global_objects/array/reduceright') diff --git a/files/zh-cn/web/javascript/reference/global_objects/array/reduceright/index.html b/files/zh-cn/web/javascript/reference/global_objects/array/reduceright/index.html index 94ef4c7602..1245486db3 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/array/reduceright/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/array/reduceright/index.html @@ -20,7 +20,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/ReduceRight

语法

-
arr.reduceRight(callback(accumulator, currentValue[, index[, array]])[, initialValue])
+
arr.reduceRight(callback(accumulator, currentValue[, index[, array]])[, initialValue])

参数

@@ -55,7 +55,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/ReduceRight

可以像下面这样调用 reduceRight 的回调函数 callback

-
array.reduceRight(function(accumulator, currentValue, index, array) {
+
array.reduceRight(function(accumulator, currentValue, index, array) {
   // ...
 });
@@ -111,7 +111,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/ReduceRight

该函数的完整执行过程见下例:

-
[0, 1, 2, 3, 4].reduceRight(function(previousValue, currentValue, index, array) {
+
[0, 1, 2, 3, 4].reduceRight(function(previousValue, currentValue, index, array) {
     return previousValue + currentValue;
 });
 
@@ -169,7 +169,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/ReduceRight

如果提供了一个 initialValue 参数,则结果如下:

-
[0, 1, 2, 3, 4].reduceRight(function(previousValue, currentValue, index, array) {
+
[0, 1, 2, 3, 4].reduceRight(function(previousValue, currentValue, index, array) {
     return previousValue + currentValue;
 }, 10);
 
@@ -235,14 +235,14 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/ReduceRight

求一个数组中所有值的和

-
var sum = [0, 1, 2, 3].reduceRight(function(a, b) {
+
var sum = [0, 1, 2, 3].reduceRight(function(a, b) {
   return a + b;
 });
 // sum is 6

扁平化(flatten)一个二维数组

-
var flattened = [[0, 1], [2, 3], [4, 5]].reduceRight(function(a, b) {
+
var flattened = [[0, 1], [2, 3], [4, 5]].reduceRight(function(a, b) {
     return a.concat(b);
 }, []);
 // flattened is [4, 5, 2, 3, 0, 1]
@@ -250,7 +250,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/ReduceRight
 
 

运行一个带有回调每个函数将其结果传给下一个的异步函数列表

-
const waterfall = (...functions) => (callback, ...args) =>
+
const waterfall = (...functions) => (callback, ...args) =>
   functions.reduceRight(
     (composition, fn) => (...results) => fn(composition, ...results),
     callback
@@ -293,7 +293,7 @@ const computation2 = (input, callback) => {
 
 

展示 reducereduceRight 之间的区别

-
var a = ['1', '2', '3', '4', '5'];
+
var a = ['1', '2', '3', '4', '5'];
 var left  = a.reduce(function(prev, cur)      { return prev + cur; });
 var right = a.reduceRight(function(prev, cur) { return prev + cur; });
 
@@ -304,7 +304,7 @@ console.log(right); // "54321"

组合函数的概念简单,它只是简单地结合了多个函数。它是一个从右向左流动的函数,用上一个函数的输出调用每个函数。

-
/**
+
/**
  * Function Composition is way in which result of one function can
  * be passed to another and so on.
  *
@@ -333,7 +333,7 @@ console.log(compose(inc, double)(2)); // 5

reduceRight 被添加到 ECMA-262 标准第 5 版,因此它在某些实现环境中可能不被支持。把下面的代码添加到脚本开头可以解决此问题,从而允许在那些没有原生支持 reduceRight 的实现环境中使用它。

-
// Production steps of ECMA-262, Edition 5, 15.4.4.22
+
// Production steps of ECMA-262, Edition 5, 15.4.4.22
 // Reference: http://es5.github.io/#x15.4.4.22
 if ('function' !== typeof Array.prototype.reduceRight) {
   Array.prototype.reduceRight = function(callback /*, initialValue*/) {
-- 
cgit v1.2.3-54-g00ecf