aboutsummaryrefslogtreecommitdiff
path: root/files/vi/web/javascript/reference/global_objects/array/reduceright
diff options
context:
space:
mode:
authorRyan Johnson <rjohnson@mozilla.com>2021-04-29 16:16:42 -0700
committerGitHub <noreply@github.com>2021-04-29 16:16:42 -0700
commit95aca4b4d8fa62815d4bd412fff1a364f842814a (patch)
tree5e57661720fe9058d5c7db637e764800b50f9060 /files/vi/web/javascript/reference/global_objects/array/reduceright
parentee3b1c87e3c8e72ca130943eed260ad642246581 (diff)
downloadtranslated-content-95aca4b4d8fa62815d4bd412fff1a364f842814a.tar.gz
translated-content-95aca4b4d8fa62815d4bd412fff1a364f842814a.tar.bz2
translated-content-95aca4b4d8fa62815d4bd412fff1a364f842814a.zip
remove retired locales (#699)
Diffstat (limited to 'files/vi/web/javascript/reference/global_objects/array/reduceright')
-rw-r--r--files/vi/web/javascript/reference/global_objects/array/reduceright/index.html347
1 files changed, 0 insertions, 347 deletions
diff --git a/files/vi/web/javascript/reference/global_objects/array/reduceright/index.html b/files/vi/web/javascript/reference/global_objects/array/reduceright/index.html
deleted file mode 100644
index 7334a47f25..0000000000
--- a/files/vi/web/javascript/reference/global_objects/array/reduceright/index.html
+++ /dev/null
@@ -1,347 +0,0 @@
----
-title: Array.prototype.reduceRight()
-slug: Web/JavaScript/Reference/Global_Objects/Array/ReduceRight
-tags:
- - JavaScr
- - Mảng
- - Phương thức
- - Thuộc tính
-translation_of: Web/JavaScript/Reference/Global_Objects/Array/ReduceRight
----
-<div>{{JSRef}}</div>
-
-<p>Phương thức <code><strong>reduceRight()</strong></code> đảo ngược các giá trị trong mảng (từ phải sang trái), xử lý và trả về một giá trị duy nhất.</p>
-
-<pre class="brush: js">var flattened = [[0, 1], [2, 3], [4, 5]].reduceRight(function(a, b) {
- return a.concat(b);
-}, []);
-
-// flattened is [4, 5, 2, 3, 0, 1]
-</pre>
-
-<p>Xem thêm {{jsxref("Array.prototype.reduce()")}} cho việc sắp xếp từ trái qua phải.</p>
-
-<h2 id="Cú_pháp">Cú pháp</h2>
-
-<pre class="syntaxbox"><var>arr</var>.reduceRight(<var>callback</var>[, <var>initialValue</var>])</pre>
-
-<h3 id="Tham_số_truyền_vào">Tham số truyền vào</h3>
-
-<dl>
- <dt><code>callback</code></dt>
- <dd>Hàm gọi thực thi mỗi giá trị của mảng, truyền vào 4 tham số:
- <dl>
- <dt><code>previousValue</code></dt>
- <dd>Giá trí trả về của hàm callback sau khi xử lý phần tử trước nó hoặc là <code>initialValue, </code>nếu như nó là phần tử đầu tiên (Xem bên dưới.)</dd>
- <dt><code>currentValue</code></dt>
- <dd>Giá trị hiện tại đang được duyệt.</dd>
- <dt><code>index</code></dt>
- <dd>Chỉ số vị trí của phần tử trong mảng.</dd>
- <dt><code>array</code></dt>
- <dd>Mảng phần tử ban đầu.</dd>
- </dl>
- </dd>
- <dt><code>initialValue</code></dt>
- <dd>Giá trị không bắt buộc. Đối tượng sử dụng cho phần tử đầu tiền của mảng, khi mà chưa có kết quả nào từ hàm <code>callback </code>trả về.</dd>
-</dl>
-
-<h3 id="Return_value">Return value</h3>
-
-<p>Giá trị trả về từ việc rút gọn.</p>
-
-<h2 id="Mô_tả">Mô tả</h2>
-
-<p><code>reduceRight</code> xử lý từng phần tử trong mảng, trừ các phần tử vô giá trị (rỗng), truyền vào 4 tham số: giá trị ban đâu (or hoặc giá trị trả về sau khi xử lý một phần tử trước đó), giá trị phần tử hiện tại, vị trí phần tử hiện tại, và giá trị mảng ban đầu.</p>
-
-<p>Việc xử lý phần tử hiện tại sẽ làm trong dấu (...) :</p>
-
-<pre class="brush: js">array.reduceRight(function(previousValue, currentValue, index, array) {
- // ... xử lý tại đây
-});
-</pre>
-
-<p>Trong lần đầu xử lý, tham số <code>previousValue</code> và <code>currentValue</code> có thể là một trong hai.</p>
-
-<ol>
- <li>Nếu tham sô <code>initialValue</code> được truyền vào <code>reduceRight</code>, thì tham số <code>previousValue</code> sẽ bằng giá trị  tham số <code>initialValue (</code>nói cách khác nó chính là<code> initialValue)</code> and <code>currentValue</code> sẽ là giá trị cuối cùng của mảng.</li>
- <li>Nếu tham số <code>initialValue</code> không được truyền vào, thì <code>previousValue</code> sẽ là giá trị cuối cùng của mảng và <code>currentValue</code> sẽ là giá trị cuối cùng thứ 2 của mảng ( giá trị thứ 2 tỉnh từ cuối mảng ).</li>
-</ol>
-
-<p>Nếu mảng rỗng và không có tham số initialValue  nào được truyền vào thì {{jsxref("TypeError")}} xảy ra. Nếu mảng chỉ có một phần tử (bất kể vị trí) à không có tham số initialValue  nào được truyền vào, hoặc nếu <code>initialValue</code> được truyền vào nhưng mảng lại rỗng, giá trị duy nhất sẽ được trả lại mà không cần tới hàm <code>callback</code>.</p>
-
-<p>Một số ví dụ mô tả luồng hoạt động của <code>reduceRight</code>, bạn có thể xem :</p>
-
-<pre class="brush: js">[0, 1, 2, 3, 4].reduceRight(function(previousValue, currentValue, index, array) {
- return previousValue + currentValue;
-});
-</pre>
-
-<p>Bảng mô tả cách xử lý phần tử trong mảng ở ví dụ trên như sau:</p>
-
-<p><em>(*Tên gọi các tham số giữ nguyên để tiện theo dõi)</em></p>
-
-<table>
- <thead>
- <tr>
- <th scope="col"><code>callback</code></th>
- <th scope="col"><code>previousValue</code></th>
- <th scope="col"><code>currentValue</code></th>
- <th scope="col"><code>index</code></th>
- <th scope="col"><code>array</code></th>
- <th scope="col">return value</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <th scope="row">lần 1</th>
- <td><code>4</code></td>
- <td><code>3</code></td>
- <td><code>3</code></td>
- <td><code>[0, 1, 2, 3, 4]</code></td>
- <td><code>7</code></td>
- </tr>
- <tr>
- <th scope="row">lần 2</th>
- <td><code>7</code></td>
- <td><code>2</code></td>
- <td><code>2</code></td>
- <td><code>[0, 1, 2, 3, 4]</code></td>
- <td><code>9</code></td>
- </tr>
- <tr>
- <th scope="row">lần 3</th>
- <td><code>9</code></td>
- <td><code>1</code></td>
- <td><code>1</code></td>
- <td><code>[0, 1, 2, 3, 4]</code></td>
- <td><code>10</code></td>
- </tr>
- <tr>
- <th scope="row">lần 4</th>
- <td><code>10</code></td>
- <td><code>0</code></td>
- <td><code>0</code></td>
- <td><code>[0, 1, 2, 3, 4]</code></td>
- <td><code>10</code></td>
- </tr>
- </tbody>
-</table>
-
-<p><code><font face="Open Sans, Arial, sans-serif">Giá trị trả về của hàm </font>reduceRight</code> sẽ là giá trị của lần thực thi cuối cùng (<code>10</code>).</p>
-
-<p>Và nếu bạn có đưa vào một giá trị <code>initialValue</code>, thì kết quả nó sẽ như thế này :</p>
-
-<pre class="brush: js">[0, 1, 2, 3, 4].reduceRight(function(previousValue, currentValue, index, array) {
- return previousValue + currentValue;
-}, 10);
-</pre>
-
-<table>
- <thead>
- <tr>
- <th scope="col"><code>callback</code></th>
- <th scope="col"><code>previousValue</code></th>
- <th scope="col"><code>currentValue</code></th>
- <th scope="col"><code>index</code></th>
- <th scope="col"><code>array</code></th>
- <th scope="col">return value</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <th scope="row">first call</th>
- <td><code>10</code></td>
- <td><code>4</code></td>
- <td><code>4</code></td>
- <td><code>[0, 1, 2, 3, 4]</code></td>
- <td><code>14</code></td>
- </tr>
- <tr>
- <th scope="row">second call</th>
- <td><code>14</code></td>
- <td><code>3</code></td>
- <td><code>3</code></td>
- <td><code>[0, 1, 2, 3, 4]</code></td>
- <td><code>17</code></td>
- </tr>
- <tr>
- <th scope="row">third call</th>
- <td><code>17</code></td>
- <td><code>2</code></td>
- <td><code>2</code></td>
- <td><code>[0, 1, 2, 3, 4]</code></td>
- <td><code>19</code></td>
- </tr>
- <tr>
- <th scope="row">fourth call</th>
- <td><code>19</code></td>
- <td><code>1</code></td>
- <td><code>1</code></td>
- <td><code>[0, 1, 2, 3, 4]</code></td>
- <td><code>20</code></td>
- </tr>
- <tr>
- <th scope="row">fifth call</th>
- <td><code>20</code></td>
- <td><code>0</code></td>
- <td><code>0</code></td>
- <td><code>[0, 1, 2, 3, 4]</code></td>
- <td><code>20</code></td>
- </tr>
- </tbody>
-</table>
-
-<p>Và tất nhiên giá trị trả về của hàm <code>reduceRight </code>sẽ là <code>20</code>.</p>
-
-<h2 id="Ví_dụ">Ví dụ</h2>
-
-<h3 id="Tính_tổng_các_giá_trị_trong_một_mảng">Tính tổng các giá trị trong một mảng</h3>
-
-<pre class="brush: js">var sum = [0, 1, 2, 3].reduceRight(function(a, b) {
- return a + b;
-});
-// sum is 6
-</pre>
-
-<h3 id="Ghép_nhiều_mảng_thành_một_mảng">Ghép nhiều mảng thành một mảng</h3>
-
-<pre class="brush: js">var flattened = [[0, 1], [2, 3], [4, 5]].reduceRight(function(a, b) {
- return a.concat(b);
-}, []);
-// flattened is [4, 5, 2, 3, 0, 1]
-</pre>
-
-<h3 id="Sự_khác_nhau_giữa_reduce_và_reduceRight">Sự khác nhau giữa <code>reduce</code> và <code>reduceRight</code></h3>
-
-<pre class="brush: js">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; });
-
-console.log(left); // "12345"
-console.log(right); // "54321"</pre>
-
-<h2 id="Polyfill">Polyfill </h2>
-
-<p><em>Đây là thuật ngữ dùng để chỉ các đoạn code được dùng để cung cấp một chức năng (hoặc công nghệ) của các trình duyệt hiện đại cho các trình duyệt cũ. Thông qua đó, các trang web sử dụng các công nghệ mới (như HTML5) có thể chạy ổn định trên các trình duyệt cũ chưa hỗ trợ.</em></p>
-
-<p><code>reduceRight</code> đã được thêm vào chuẩn ECMA-262 trong lần sửa đổi thứ 5; do đó có thể nó không xuất hiện trong các trình duyệt chưa hỗ trợ nó . Bạn có thể dùng <code>reduceRight </code>bằng việc thêm đoạn mã sau vào code của bạn với khi làm việc với các trình duyệt không hỗ trợ nó.</p>
-
-<pre class="brush: js">// 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*/) {
- 'use strict';
- if (null === this || 'undefined' === typeof this) {
- throw new TypeError('Array.prototype.reduce called on null or undefined');
- }
- if ('function' !== typeof callback) {
- throw new TypeError(callback + ' is not a function');
- }
- var t = Object(this), len = t.length &gt;&gt;&gt; 0, k = len - 1, value;
- if (arguments.length &gt;= 2) {
- value = arguments[1];
- } else {
- while (k &gt;= 0 &amp;&amp; !(k in t)) {
- k--;
- }
- if (k &lt; 0) {
- throw new TypeError('Reduce of empty array with no initial value');
- }
- value = t[k--];
- }
- for (; k &gt;= 0; k--) {
- if (k in t) {
- value = callback(value, t[k], k, t);
- }
- }
- return value;
- };
-}
-</pre>
-
-<h2 id="Điều_khoản">Điều khoản</h2>
-
-<table class="standard-table">
- <tbody>
- <tr>
- <th scope="col">Specification</th>
- <th scope="col">Status</th>
- <th scope="col">Comment</th>
- </tr>
- <tr>
- <td>{{SpecName('ES5.1', '#sec-15.4.4.22', 'Array.prototype.reduceRight')}}</td>
- <td>{{Spec2('ES5.1')}}</td>
- <td>Initial definition. Implemented in JavaScript 1.8.</td>
- </tr>
- <tr>
- <td>{{SpecName('ES6', '#sec-array.prototype.reduceright', 'Array.prototype.reduceRight')}}</td>
- <td>{{Spec2('ES6')}}</td>
- <td> </td>
- </tr>
- <tr>
- <td>{{SpecName('ESDraft', '#sec-array.prototype.reduceright', 'Array.prototype.reduceRight')}}</td>
- <td>{{Spec2('ESDraft')}}</td>
- <td> </td>
- </tr>
- </tbody>
-</table>
-
-<h2 id="Trình_duyệt_hỗ_trợ">Trình duyệt hỗ trợ</h2>
-
-<div>{{CompatibilityTable}}</div>
-
-<div id="compat-desktop">
-<table class="compat-table">
- <tbody>
- <tr>
- <th>Feature</th>
- <th>Chrome</th>
- <th>Firefox (Gecko)</th>
- <th>Internet Explorer</th>
- <th>Opera</th>
- <th>Safari</th>
- </tr>
- <tr>
- <td>Basic support</td>
- <td>{{CompatVersionUnknown}}</td>
- <td>{{CompatGeckoDesktop("1.9")}}</td>
- <td>{{CompatIE("9")}}</td>
- <td>{{CompatOpera("10.5")}}</td>
- <td>{{CompatSafari("4.0")}}</td>
- </tr>
- </tbody>
-</table>
-</div>
-
-<div id="compat-mobile">
-<table class="compat-table">
- <tbody>
- <tr>
- <th>Feature</th>
- <th>Android</th>
- <th>Chrome for Android</th>
- <th>Firefox Mobile (Gecko)</th>
- <th>IE Mobile</th>
- <th>Opera Mobile</th>
- <th>Safari Mobile</th>
- </tr>
- <tr>
- <td>Basic support</td>
- <td>{{CompatVersionUnknown}}</td>
- <td>{{CompatVersionUnknown}}</td>
- <td>{{CompatVersionUnknown}}</td>
- <td>{{CompatVersionUnknown}}</td>
- <td>{{CompatVersionUnknown}}</td>
- <td>{{CompatVersionUnknown}}</td>
- </tr>
- </tbody>
-</table>
-</div>
-
-<h2 id="sect1"> </h2>
-
-<h2 id="Xem_thêm">Xem thêm</h2>
-
-<ul>
- <li>{{jsxref("Array.prototype.reduce()")}}</li>
-</ul>