given [40, 10, 30] let min = first elem = 40 iterate through elements We'll start at second position (first would also work) 40 < 40 no 10 < 40 yes let min=10 30 < 10 no final min = 10
testMin() { const unit = new Stats([40, 10, 30, 20]); this.assertEquals(10, unit.min()); } testMinCountOne() { const unit = new Stats([40]); this.assertEquals(40, unit.min()); } testMinEmptyCase() { const unit = new Stats([]); this.assertEquals(null, unit.min()); }
let count = this.count() if (count == 0) return null
nums = this.nums min = nums[0] i = 1 while (i < nums.length) next = nums[i] if (next < min) min = next i++ return min