Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
function concat(arrays) {
// sum of individual array lengths
// soma dos comprimentos individuais dos arrays
let totalLength = arrays.reduce((acc, value) => acc + value.length, 0);

let result = new Uint8Array(totalLength);

if (!arrays.length) return result;

// for each array - copy it over result
// next array is copied right after the previous one
// para cada array - copie-o sobre o resultado
// O próximo array é copiado imediatamente após o anterior.
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...
// ...seu código...
}

let chunks = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ describe("concat", function() {
new Uint8Array([6, 7, 8])
];

it("result has the same array type", function() {
it("resultado possui o mesmo tipo de array", function() {

let result = concat(chunks);

assert.equal(result.constructor, Uint8Array);
});

it("concatenates arrays", function() {
it("concatena arrays", function() {

let result = concat(chunks);

assert.deepEqual(result, new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8]));

});

it("returns empty array on empty input", function() {
it("Retorna um array vazio se a entrada estiver vazia.", function() {

let result = concat([]);

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
# Concatenar arrays tipados

Given an array of `Uint8Array`, write a function `concat(arrays)` that returns a concatenation of them into a single array.
Dado um array de `Uint8Array`, escreva uma função `concat(arrays)` que retorna uma concatenação deles em um único array.
Loading