Challenge - 5 Problems
Typed Array Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of Typed Array Initialization
What is the output of this TypeScript code snippet using a typed array?
Typescript
const arr = new Uint8Array([10, 20, 300]); console.log(arr);
Attempts:
2 left
💡 Hint
Remember that Uint8Array stores values as 8-bit unsigned integers, so values above 255 wrap around.
✗ Incorrect
Uint8Array stores numbers between 0 and 255. The value 300 wraps around modulo 256, so 300 % 256 = 44.
🧠 Conceptual
intermediate2:00remaining
Why Use Typed Arrays Instead of Normal Arrays?
Which of the following is the main reason to use typed arrays like Uint16Array over normal JavaScript arrays?
Attempts:
2 left
💡 Hint
Think about performance and memory when working with binary data.
✗ Incorrect
Typed arrays provide fixed-size buffers with elements of a single type, making them efficient for binary data and interfacing with low-level APIs.
🔧 Debug
advanced2:00remaining
Debug Typed Array Element Assignment
What error or output will this TypeScript code produce?
Typescript
const buffer = new ArrayBuffer(4); const view = new Uint16Array(buffer); view[0] = 65536; console.log(view[0]);
Attempts:
2 left
💡 Hint
Consider the size limit of Uint16Array elements and how values are stored.
✗ Incorrect
Uint16Array elements store 16-bit unsigned integers (0 to 65535). Assigning 65536 wraps around to 0 because 65536 % 65536 = 0.
📝 Syntax
advanced2:00remaining
Identify Syntax Error in Typed Array Declaration
Which option contains a syntax error when declaring a typed array in TypeScript?
Attempts:
2 left
💡 Hint
Check the brackets used for array initialization.
✗ Incorrect
Typed arrays must be initialized with parentheses and either an array or a length. Curly braces {} are invalid syntax here.
🚀 Application
expert3:00remaining
Calculate Sum of Elements in a Typed Array
Given the following TypeScript code, what is the value of sum after execution?
Typescript
const data = new Int8Array([-128, 127, 1, -1]); let sum = 0; for (const num of data) { sum += num; } console.log(sum);
Attempts:
2 left
💡 Hint
Add the numbers carefully considering their signed 8-bit values.
✗ Incorrect
Sum is (-128) + 127 + 1 + (-1) = -1.