How would you sort through an array, which also contains 0 values i.e.
- -54
- 0
- -12
- 0
- -10
and comparing it to a constant (say -5), which would return the index of the corresponding closest value (smallest difference) ? (i.e. closest value = -10, so returned value = 4)
The challenge here being 0 values should always be overlooked, and the array cannot be sorted before hand
Heres a Similar problem, answers for which doesn't quite work in my case How do I find the closest array element to an arbitrary (non-member) number?