shelf.ts 466 B

12345678910111213141516171819202122
  1. /* There are lots of shelves in the library, and they can contain different
  2. types of objects.
  3. */
  4. export default class Shelf<T> {
  5. private _items: Array<T> = new Array<T>();
  6. add(item: T): void {
  7. this._items.push(item);
  8. }
  9. find(title: string): T {
  10. return this._items.filter(item => item.title === title)[0];
  11. }
  12. getFirst(): T {
  13. return this._items[0];
  14. }
  15. printTitles(): void {
  16. this._items.forEach(item => console.log(item.title));
  17. }
  18. }