Skip to content
Merged
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
function concat(arrays) {
// sum of individual array lengths
// 对每个数组长度求和
let totalLength = arrays.reduce((acc, value) => acc + value.length, 0);

if (!arrays.length) return null;

let result = new Uint8Array(totalLength);

// for each array - copy it over result
// next array is copied right after the previous one
// 对于每个数组 — 复制到 result
// 下一个数组在前一个后面复制
let length = 0;
for(let array of arrays) {
result.set(array, length);
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
function concat(arrays) {
// ...your code...
// ……你的代码……
}

let chunks = [
Expand Down
4 changes: 2 additions & 2 deletions 4-binary/01-arraybuffer-binary-arrays/01-concat/task.md
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@

# Concatenate typed arrays
# 拼接类型化数组(Concatenate typed arrays

Given an array of `Uint8Array`, write a function `concat(arrays)` that returns a concatenation of them into a single array.
给定一个 `Uint8Array` 数组,请写一个函数 `concat(arrays)`,将数组拼接成一个单一数组并返回。
Loading