Fun One Liners

Ok… cool, but is there is also a method returning the indexes of values close to the given ones like :

b= [-1, 0, 1.2, 2.1, 3.5, 4.87, 5.1, 6, 7, 8]
a = [1, 2, 6, 3]
julia> indexnear(a, b)
4-element Array{Union{Nothing, Int64},1}:
 3
 4
 8
 5

here i can simply use (m-> findfirst(x -> x >= m ,b)).(a)
how ever this solution is far from being perfect

EDIT: Find indexes of elements in array b close to those in array a
With the help of this thread
we can do:

(m-> findmin(abs.(a.-m))[2]).(b)

1 Like