mirror of
https://github.com/microsoft/frontend-bootcamp.git
synced 2026-01-26 14:56:42 +08:00
adding exercies for steps 2-1 and 2-2
This commit is contained in:
23
step2-01/demo/src/generics/index.ts
Normal file
23
step2-01/demo/src/generics/index.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
// Generics for classes
|
||||
class Stack<T = number> {
|
||||
private data: T[] = [];
|
||||
|
||||
push(item: T) {
|
||||
this.data.push(item);
|
||||
}
|
||||
pop(): T {
|
||||
return this.data.pop();
|
||||
}
|
||||
}
|
||||
|
||||
const numberStack = new Stack();
|
||||
const stringStack = new Stack<string>();
|
||||
|
||||
// Generics for functions
|
||||
function reverse<T>(arg: T[]): T[] {
|
||||
// TODO: implement the logic to reverse the array
|
||||
return arg;
|
||||
}
|
||||
|
||||
// adding an export to turn this into a "module"
|
||||
export default {};
|
||||
Reference in New Issue
Block a user