Created
July 25, 2022 10:32
-
-
Save semlinker/dd9d21a106d8ea42f9e3d5394aae1cd1 to your computer and use it in GitHub Desktop.
Concatenate Function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function concatenate(arrays) { | |
if (!arrays.length) return null; | |
let totalLength = arrays.reduce((acc, value) => acc + value.length, 0); | |
let result = new Uint8Array(totalLength); | |
let length = 0; | |
for (let array of arrays) { | |
result.set(array, length); | |
length += array.length; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment