Skip to content

ArrayBuffer, binary arrays #529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Dec 5, 2019
Merged
Original file line number Diff line number Diff 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 number Diff line number Diff 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 number Diff line number Diff 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