(_iterable, _selector = undefined)
| 4 | */ |
| 5 | |
| 6 | const FindMinIterator = (_iterable, _selector = undefined) => { |
| 7 | let min |
| 8 | |
| 9 | const iterator = _iterable[Symbol.iterator]() |
| 10 | if (!_selector) { |
| 11 | let current = iterator.next() |
| 12 | if (current.done) { |
| 13 | return undefined |
| 14 | } |
| 15 | min = current.value |
| 16 | |
| 17 | current = iterator.next() |
| 18 | while (!current.done) { |
| 19 | const x = current.value |
| 20 | if (x < min) { |
| 21 | min = x |
| 22 | } |
| 23 | current = iterator.next() |
| 24 | } |
| 25 | } else { |
| 26 | let current = iterator.next() |
| 27 | if (current.done) { |
| 28 | return undefined |
| 29 | } |
| 30 | min = _selector(current.value) |
| 31 | |
| 32 | current = iterator.next() |
| 33 | while (!current.done) { |
| 34 | const x = _selector(current.value) |
| 35 | if (x < min) { |
| 36 | min = x |
| 37 | } |
| 38 | current = iterator.next() |
| 39 | } |
| 40 | } |
| 41 | return min |
| 42 | } |
| 43 | |
| 44 | export { FindMinIterator } |
no outgoing calls
no test coverage detected