aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/array/flat
diff options
context:
space:
mode:
authort7yang <t7yang@gmail.com>2022-01-10 08:38:07 +0800
committerIrvin <irvinfly@gmail.com>2022-02-16 02:35:54 +0800
commit563ca0a35e98678e2b7d5f154f31f496851e8d60 (patch)
tree7c99e7e037128217eca2080df671a742076c615b /files/zh-cn/web/javascript/reference/global_objects/array/flat
parentd7b2995cabe8d85a1827aa18bc270bdf739f3d13 (diff)
downloadtranslated-content-563ca0a35e98678e2b7d5f154f31f496851e8d60.tar.gz
translated-content-563ca0a35e98678e2b7d5f154f31f496851e8d60.tar.bz2
translated-content-563ca0a35e98678e2b7d5f154f31f496851e8d60.zip
remove code tag inside pre tag for zh-CN
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/array/flat')
-rw-r--r--files/zh-cn/web/javascript/reference/global_objects/array/flat/index.html12
1 files changed, 5 insertions, 7 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/array/flat/index.html b/files/zh-cn/web/javascript/reference/global_objects/array/flat/index.html
index f6a9420e21..4f06aff1fc 100644
--- a/files/zh-cn/web/javascript/reference/global_objects/array/flat/index.html
+++ b/files/zh-cn/web/javascript/reference/global_objects/array/flat/index.html
@@ -78,16 +78,14 @@ const flattened = arr =&gt; [].concat(...arr);</code></pre>
<h3 class="brush: js" id="reduce_concat_isArray_recursivity">reduce + concat + isArray + recursivity</h3>
-<pre class="brush: js"><code>// 使用 reduce、concat 和递归展开无限多层嵌套的数组
-var arr1 = [1,2,3,[1,2,3,4, [2,3,4]]];
-</code>
-<code class="language-js">function flatDeep(arr, d = 1) {
+<pre class="brush: js">// 使用 reduce、concat 和递归展开无限多层嵌套的数组
+ var arr1 = [1,2,3,[1,2,3,4, [2,3,4]]];
+function flatDeep(arr, d = 1) {
return d &gt; 0 ? arr.reduce((acc, val) =&gt; acc.concat(Array.isArray(val) ? flatDeep(val, d - 1) : val), [])
: arr.slice();
-};</code>
-<code>
+};
flatDeep(arr1, Infinity);
-// [1, 2, 3, 1, 2, 3, 4, 2, 3, 4]</code></pre>
+// [1, 2, 3, 1, 2, 3, 4, 2, 3, 4]</pre>
<h3 id="forEachisArraypushrecursivity">forEach+isArray+push+recursivity</h3>