cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

getting multiple occurrences of an item in a list as a list

Does anyone knows what is the function to get multiple of occurrences of an item in a list as list of indexes.

example:

with fun(iList,"item") as occurencesOfItem

unwind occurencesOfItems

....

1 ACCEPTED SOLUTION

I am not sure I understand your requirement. I think you want a method of deriving the indexes of a given item from a list of elements. If so, the following demonstrates a solution for a list of integers. The result of executing the cypher is [2,4], which is index positions of each occurrence of '6'.

with [3, 4, 6, 2, 6, 3, 7] as x, 6 as item
return [i in range(0,size(x)-1) where x[i] = item] as indexes

Is this what you are looking for?

View solution in original post

2 REPLIES 2

I am not sure I understand your requirement. I think you want a method of deriving the indexes of a given item from a list of elements. If so, the following demonstrates a solution for a list of integers. The result of executing the cypher is [2,4], which is index positions of each occurrence of '6'.

with [3, 4, 6, 2, 6, 3, 7] as x, 6 as item
return [i in range(0,size(x)-1) where x[i] = item] as indexes

Is this what you are looking for?

I replied earlier but the reply lost.

thank you so much glilienfield. it amazing. it works great!!.