# How to count the interval number in sites not using for loop and push!?

**URL:** <https://discourse.julialang.org/t/how-to-count-the-interval-number-in-sites-not-using-for-loop-and-push/90738>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 24, 2022, 2:50am UTC](https://discourse.julialang.org/t/how-to-count-the-interval-number-in-sites-not-using-for-loop-and-push/90738 "2022-11-24T02:50:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhangchunyong](https://avatars.discourse-cdn.com/v4/letter/z/d9b06d/32.png) [@zhangchunyong](https://discourse.julialang.org/u/zhangchunyong)\
**Post date:** [November 24, 2022, 2:50am UTC](https://discourse.julialang.org/t/how-to-count-the-interval-number-in-sites-not-using-for-loop-and-push/90738/1 "2022-11-24T02:50:03Z")

</div>

I have an interval and some sites,I want to judge whether each of the interval are in sites,and finally count the number.like the following

```julia
using BenchmarkTools
intervals=10650:10699
sites=[10673,10655,10662,10670,10650,10691,10694,10689,10660,10667,10679]
function m(intervals,sites)
    b=Bool[]
    for i in intervals
        if i in sites
            push!(b,true)
        else
            push!(b,false)
        end
    end
    sum(b)
end
julia> @btime m($intervals,$sites)
  566.754 ns (4 allocations: 352 bytes)
11

```

I got an easier way.But it was slower.

```julia
julia> @btime length(intersect($intervals,$sites))
  1.979 μs (21 allocations: 3.48 KiB)
11

```

Are there any easier ways (not using for loop as well as push!)?Thanks for helping me!

---

<div class="post-metadata">

**Author:** ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)\
**Post date:** [November 24, 2022, 3:10am UTC](https://discourse.julialang.org/t/how-to-count-the-interval-number-in-sites-not-using-for-loop-and-push/90738/2 "2022-11-24T03:10:43Z")

</div>

Try:

```julia
count(∈(intervals), sites)

```

(∈ is typed \in in REPL)
