Using the code from this answer to find the closest value in an array: https://stackoverflow.com/a/62159057
func closestMatch(values: [Int64], inputValue: Int64) -> Int64? {
return (values.reduce(values[0]) { abs($0-inputValue) < abs($1-inputValue) ? $0 : $1 })
}
How can I get the index of the item that matches closest instead of its value?