* Returns the first n items in sorted order (from the start)
(n: number, filterFn?: (key: TKey) => boolean)
| 423 | * Returns the first n items in sorted order (from the start) |
| 424 | */ |
| 425 | takeFromStart(n: number, filterFn?: (key: TKey) => boolean): Array<TKey> { |
| 426 | const result: Array<TKey> = [] |
| 427 | for (let i = 0; i < this.sortedValues.length && result.length < n; i++) { |
| 428 | const keys = this.valueMap.get(this.sortedValues[i]) |
| 429 | if (keys) { |
| 430 | for (const key of keys) { |
| 431 | if (result.length >= n) break |
| 432 | if (!filterFn || filterFn(key)) { |
| 433 | result.push(key) |
| 434 | } |
| 435 | } |
| 436 | } |
| 437 | } |
| 438 | return result |
| 439 | } |
| 440 | |
| 441 | /** |
| 442 | * Returns the first n items in reverse sorted order (from the end) |
no test coverage detected