[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] array processing



Hi Martin, since there is no fixed algorithm in your concatenation scheme, this is not a single looping structure but the .collect and the ++ operator for concatenating arrays and symbols (and strings) are your friends here, something like this:

a = [ '/pen/0', [ [ '/0', '/1', '/2', '/3', '/4' ], '/button', [ '/1', '/2', '/3' ], '/proximity' ], '/key', [ '/1', '/2', '/3', '/4' ] ]

a[1][0].collect({|item| a[0]++item; }) ++ a[1][2].collect({|item| a[0]++a[1][1]++item }) ++ [a[0] ++ a[1][3]] ++ a[3].collect({|item| a[2]++item })
 
Batuhan Bozkurt




On Jul 28, 2009, at 8:26 AM, Martin Marier wrote:

Hello list,

I'm stuck on what seemed to be a simple problem at first.  There must be a simple solution...

I want an array structured like this :

[ /pen/0, [ [ /0, /1, /2, /3, /4 ], /button, [ /1, /2, /3 ], /proximity ], /key, [ /1, /2, /3, /4 ] ]

to end up like this :

[ /pen/0/0, /pen/0/1, /pen/0/2, /pen/0/3, /pen/0/4, /pen/0/button/1, /pen/0/button/2, /pen/0/button/3, /pen/0/proximity, /key/1, /key/2, /key/3, /key/4 ]




It is clearer presented this way (I think):

[ /pen/0,
[
[ /0, /1, /2, /3, /4 ],
/button,
[ /1, /2, /3 ],
/proximity
],
/key,
[ /1, /2, /3, /4 ]
]

Any suggestions ?

Martin Marier

_______________________________________________
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/