Clamp them all
Inputs
values is a list of 0 to 12 whole numbers, each from -20 to 40. low is from -10 to 10 and high is from 11 to 30.
Your tasks
- Create an empty list
clamped. - Use a loop over
values. Addlowif the number is belowlow, addhighif it is abovehigh, and add the number itself otherwise. - Complete
clampAllso it returnsclamped. Return it, do not print it.
Example
With values = [-5, 3, 18, 40, 9] and low = 0 and high = 20, clampAll returns [0, 3, 18, 20, 9].
Rules
- Keep the original order.
Test data
TEST DATA 1: values is [-5, 3, 18, 40, 9], low is 0, high is 20
TEST DATA 2: values is [], low is 0, high is 20
Practice focus
Put an if inside the loop to keep, skip or change items. Filtering, mapping and comparing neighbours show up in nearly every array question.