Last active
November 8, 2023 15:18
-
-
Save trikitrok/632121a7af7eb1d30f9f1e4e4adcccbb to your computer and use it in GitHub Desktop.
This file contains 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
// From Rachel M. Carmena's https://github.com/rachelcarmena/code-smells | |
class CoolStack<T> extends Array { | |
push(...items: T[]): number { | |
return super.push(...items); | |
} | |
public pop(): T { | |
return super.pop(); | |
} | |
} | |
//---------------------------------------------------------------------------- | |
//---------------------------------------------------------------------------- | |
class CoolStack<T> { | |
private readonly elements: T[]; | |
constructor() { | |
this.elements = new Array<T>(); | |
} | |
push(...items: T[]): number { | |
this.elements.push(...items); | |
return this.elements.length; | |
} | |
pop(): T { | |
const element = this.elements[this.elements.length-1]; | |
this.elements.pop(); | |
return element; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment