[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [sc-users] Using value from array to select elements in another array
Am 31.12.2012 um 06:54 schrieb xiaoping lyu:
A = [14, 2, 9, 1, 11, 8, 12, 4, 4]
| |
B = [1, 2, 3, 1, 2, 4, 1, 3, 4]
Hi,
coupling the lists (flop) makes it practical, e.g.
a = [14, 2, 9, 1, 11, 8, 12, 4, 4];
b = [1, 2, 3, 1, 2, 4, 1, 3, 4];
c = [a,b].flop;
c.select { |x| x[1]==3 }.choose.first
You could define a function for that.
A matter of preference if to make the coupling
inside or outside the function.
~myChoose = { |pairs, eqlNum|
pairs.select { |x| x.last==eqlNum }.choose.first
}
~myChoose.(c, 3)
~myChoose.(c, 5)
Greetings
Daniel
-----------------------------
http://daniel-mayer.at
-----------------------------
_______________________________________________
sc-users mailing list
info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: https://listarc.bham.ac.uk/marchives/sc-users/
search: https://listarc.bham.ac.uk/lists/sc-users/search/