这个 达雷。reduceRight() 是JavaScript中的一个内置函数,用于将typedArray的每个元素从右向左缩减为一个值。 语法:
null
typedArray.reduceRight(callback)
参数: 它接受一个参数回调函数,该函数接受下面指定的一些参数-
- 以前的值: 它是之前返回的值。
- 当前值: 它是typedArray中正在处理的当前元素。
返回值: 它返回reduceRight()函数的结果。
<script> // Creating some typedArray const A = new Uint8Array([ 1, 2, 3, 4]); const B = new Uint8Array([5, 6, 7]); const C = new Uint8Array([1, 3, 5]); const D = new Uint8Array([2, 4, 6, 8]); // Calling sum() function function sum(previousValue, currentValue) { return previousValue + currentValue; } // Printing reduced value of the given typedArray document.write(A.reduceRight(sum) + "<br>" ); document.write(B.reduceRight(sum) + "<br>" ); document.write(C.reduceRight(sum) + "<br>" ); document.write(D.reduceRight(sum)); </script> |
输出:
10 18 9 20
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END