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