Find the smallest
Inputs
values is a list of 1 to 12 whole numbers, each from -50 to 50.
Your tasks
- Create a number
lowand set it to the first number invalues. - Use a loop over
values. Whenever a number is smaller thanlow, replacelowwith it. - Complete
smallestso it returnslow. Return it, do not print it.
Example
With values = [3, 9, -2, 9, 5], smallest returns -2.
Rules
valuesalways has at least one number.
Test data
TEST DATA 1: values is [3, 9, -2, 9, 5]
TEST DATA 2: values is [8, 3, 20]
Practice focus
One pass over a list to add, count, find the biggest and the smallest. Scanning an array once and keeping a running answer is the backbone of linear-time solutions.