* Extracts a slice of the collection items starting at position start to end (exclusive) of the collection. * If end is null it returns all elements from start to the end of the collection.
(start = 0, end?: number)
| 704 | * If end is null it returns all elements from start to the end of the collection. |
| 705 | */ |
| 706 | slice(start = 0, end?: number): T[] { |
| 707 | this.checkInitialized(); |
| 708 | let index = 0; |
| 709 | end ??= this.#items.size; |
| 710 | const items: T[] = []; |
| 711 | |
| 712 | for (const item of this.#items) { |
| 713 | if (index === end) { |
| 714 | break; |
| 715 | } |
| 716 | |
| 717 | if (index >= start && index < end) { |
| 718 | items.push(item); |
| 719 | } |
| 720 | |
| 721 | index++; |
| 722 | } |
| 723 | |
| 724 | return items; |
| 725 | } |
| 726 | |
| 727 | /** |
| 728 | * Tests for the existence of an element that satisfies the given predicate. |