Index
Overview


The min is the minimum element in a list of numbers.

As always, the solutions shown are not the only solutions (there may be are many).

Also see suggested approach....

Manual Solutions


This is often what we will do first when using a recipe approach

These old pencil-and-paper style manual solutions are often our best friends.

We simply iterate through the list looking for the smallest (min) number.
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


Unit Tests


We'll take a test first approach.

Example Tests
Just this small group of tests covers a lot of the scenarios for 'mode'.
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());
}



Recipe


Special Cases
Eliminate special cases right away. That simplifies the rest of the recipe.
let count = this.count()
if (count == 0) return null
Solving
We were able to basically just follow our manual solution here.
nums = this.nums
min = nums[0]
i = 1
while (i < nums.length)
	next = nums[i]
	if (next < min)
		min = next
	i++
return min