# Fwd: In search of elegant indices searching

**URL:** <https://www.ruby-forum.com/t/fwd-in-search-of-elegant-indices-searching/60636>\
**Category:** Ruby\
**Created:** [May 16, 2006, 1:07pm UTC](https://www.ruby-forum.com/t/fwd-in-search-of-elegant-indices-searching/60636 "2006-05-16T13:07:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tbobker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/73ab20/32.png) [@tbobker](https://www.ruby-forum.com/u/tbobker)\
**Post date:** [May 16, 2006, 1:07pm UTC](https://www.ruby-forum.com/t/fwd-in-search-of-elegant-indices-searching/60636/1 "2006-05-16T13:07:08Z")

</div>

Your result is confusing me:

> {{‘x’=\>1,‘w’=\>1}=\>[0,3],{‘x’=\>3,‘w’=\>3}=\>[2],{‘x’=\>5,‘w’=\>4}=\>[4],{‘x’=\>6,  
> ‘w’=\>5}=\>[5]}.

Not really sure what you’re trying to accomplish, if you want to  
determine the indices at which two arrays contain identical values,  
you could try:

def comp arr1, arr2  
res=[]  
arr1.each\_with\_index {|val, i|  
res.push val==arr2[i]  
}  
end  
comp [1,1,3,1,5,6], [1,2,3,1,4,5] # -\> [true, false, true, true, false,  
false]

if you’d like to determine which values occur in both arrays, try the  
intersection operator `&`:

[1,1,3,1,5,6] & [1,2,3,1,4,5] # -\> [1, 3, 5]

-tim
