Question: I have an array of arrays:

```
[
  [0,0,0,0],
  [0,1,0,0],
  [0,0,0,1],
  [0,0,0,0]
]

```

I want to find the index (row and column) of the items with value `1`. How can I do this? I need these values so that I can manipulate the cells at either side of the `1`s. I looked at `find.index` method, but I'm not sure.

Answer: 
Not that fancy, but you could use two loops:

```
ary = [
  [0, 0, 0, 0],
  [0, 1, 0, 0],
  [0, 0, 0, 1],
  [0, 0, 0, 0]
]

result = []
ary.each_with_index do |row, i|
  row.each_with_index do |value, j|
    result << [i, j] if value == 1
  end
end
result
#=> [[1, 1], [2, 3]]

```
Ruby has a very flexible, functional style `Enumerable` module which is included in many of the standard collections (Arrays, Hashes, Sets). You can find the documentation [at ruby-doc.org](http://ruby-doc.org/core-2.3.0/Enumerable.html). 

A nice one-liner to solve this in max #rows \* 2 #columns time would be the following:

```
matrix
  .each.with_index
  .inject([]) { |acc, (el,idx)| el.include?(1) ? acc.push([idx, el.index(1)]) : acc }
# => [[1,1],[2,3]]

```