Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Last active November 8, 2023 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trikitrok/632121a7af7eb1d30f9f1e4e4adcccbb to your computer and use it in GitHub Desktop.
Save trikitrok/632121a7af7eb1d30f9f1e4e4adcccbb to your computer and use it in GitHub Desktop.
// 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