Skip to main content
TypeScript Code Reorder Hard +35 XP

Generic Class

Arrange the generic stack class.

Click lines in the correct order

Available lines6 left

Your order

Click lines above to build your solution.

Show answer and explanation

Answer: class Stack<T> { private items: T[] = []; push(item: T): void { this.items.push(item); } pop(): T | undefined { return this.items.pop(); } get size(): number { return this.items.length; } }

Class with generic, then private state, then push, pop, and size getter.

Hint: Private state first, then methods.

What this challenge tests

Code Reorder in TypeScript: generics, classes, data-structures.

Related challenges