Finding the value closest to 0
Question
Suppose you are given a list of Q
1D points. Write code to return the value in Q
that is the closest to value j
. If two values are equally close to j
, return the smaller value.
Example:
Q = [1, -1, -5, 2, 4, -2, 1]
j = 3
#Output: 2