diff --git a/base/array.jl b/base/array.jl index 38470555cb899..c124349448a45 100644 --- a/base/array.jl +++ b/base/array.jl @@ -2230,11 +2230,13 @@ julia> indexin(b,a) 3 ``` """ -function indexin(a::AbstractArray, b::AbstractArray) +function indexin(a, b::AbstractArray) bdict = Dict(zip(b, 1:length(b))) [get(bdict, i, 0) for i in a] end +indexin(a::T, b::AbstractArray{T}) where {T} = findlast(b, a) + function _findin(a, b) ind = Int[] bset = Set(b) diff --git a/test/arrayops.jl b/test/arrayops.jl index f0e6e589f6289..60e23230a6ff2 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -1373,6 +1373,11 @@ end # PR #8622 and general indexin tests @test indexin([1,3,5,7], [5,4,3]) == [0,3,1,0] @test indexin([1 3; 5 7], [5 4; 3 2]) == [0 2; 1 0] +@test indexin((2 * x + 1 for x in 0:3), [5,4,3,5,6]) == [0,3,4,0] +@test indexin(6, [1,3,6,6,2]) == 4 +@test indexin([6], [1,3,6,6,2]) == [4] +@test indexin(3, 2:5) == 2 +@test_broken indexin(3.0, 2:5) == 2 #6828 - size of specific dimensions let a = Array{Float64}(10)