Ruby array of arrays find by inner array value

Krzysztof Witczak

I have array of arrays, which looks like this:

a = [['1','1500','SomeName','SomeSurname'],
['2','1500','SomeName2','SomeSurname2'],
['3','1500','SomeName3','SomeSurname3'],
['4','1501','SomeName','SomeSurname'],
...]

I can get sub-array of this array with all rows containing '1500' value by .each function and simple if, but if a.length is large, it's taking too much time! How can I get all rows from a with certain a[1] value, without iterating over a?

Andrey Deineko

Enumerable#find_all is what you are looking for:

a.find_all { |el| el[1] == '1500' } # a.select will do the same

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Ruby inner flatten (array of arrays)

From Dev

Sort array of arrays by array value into hash in ruby

From Dev

Find all permutations of Ruby array of arrays

From Dev

Find first value of inner array based on second value

From Dev

Ruby - Array.find, but return the value the block

From Dev

Filtering array by inner array value

From Dev

Ruby: Array of Arrays to Array of Hashes

From Dev

Ruby: Array of Arrays to Array of Hashes

From Dev

Sorting an array of array by a certain value in the inner array

From Dev

find row in ruby array

From Dev

Find a Duplicate in an array Ruby

From Dev

ruby find entry in array

From Dev

find row in ruby array

From Dev

Set inner value for multidimensional array

From Dev

Set inner value for multidimensional array

From Dev

Custom arrays compare or find value which is not exist in another array with linq

From Dev

how to search in array to find all sub arrays that contain a certain value

From Dev

Ruby group_by in array of arrays

From Dev

Array of arrays element comparison Ruby

From Dev

Ruby array of arrays and nil guard

From Dev

Transforming an array of arrays to an array of hashes in Ruby

From Dev

Ruby converting array of hashes to array of arrays

From Dev

Ruby: map array of strings into array of arrays

From Dev

merge recursive on inner arrays of multidimensional array php

From Dev

AngularJS Order JSON array and inner arrays

From Dev

Ruby use find to loop through an array and return the matching value

From Dev

How to find, return and remove the maximum value from an array in Ruby?

From Dev

Ruby/Rails: Convert array of arrays to hash of arrays

From Dev

Find the index of the longest array in an array of arrays

Related Related

HotTag

Archive