ruby - How do I find .index of a multidimensional array -
Tried web resources and I had no luck and my visual quick start guide.
If I have 2D / multi-dimensional array:
array = [['x', 'x', 'x', 'x'], ['x '' '' '' '' '' '' '', '' '', '', 'X'], ['x', 'x', 'x', 'x']] print array.Andx ('s') returns zero
/ Pre>Then I will go and type:
array = ['x', 's', '', 'x'] print array. Index 's'
It values what I'm looking for 1
My first guess is that .exex is being said incorrectly and it's going to be two lines and Columns Need two arguments for? Either way how do I work for a multi-dimensional array? This is a step to solve my little maze problem
a.each_index {| I | J = a [i]. Index 's'; P [i, j] if j}
Update: OK, we can return many matches. Possibly the use of core APIs is possible, repeat it with the translated ruby code one by one, let's add some short-circuit exits and add the etterable eval to break the row into pieces. This time it is organized on an array as an instance method, and it gives an array of [row, cola] subroutes.
a = [% w {abcd},% w {s},% w {sss xyz},% w {SSSSSS},% w {xyz s},% w {xy s} AB},% w {x},% w {}} Identify the square array DF 2D test R = [] each_ index. I Row, j0 = self [i], 0 while row.include? Test if j = (line.inx test) r & lt; & Lt; [I, j0 + j] j + = 1 j0 + = j line = row.drop j end end end end end and end and p a.locate2d 's'
Comments
Post a Comment