Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

Append array indexes in ruby?

For general discussion related FlowStone

Append array indexes in ruby?

Postby kortezzzz » Wed Sep 28, 2016 3:01 pm

Hi,

Is there any way to append array indexes in ruby?

My arrays:

array 1:

red
green
white

array 2:

tomato
frog
snow

I would like to get at the output :

red tomato
green frog
white snow

I guess the comma between the indexes in the final result should be also defined in the ruby code, so would be nice if we could add a 3th input in to this ruby code which would define the comma.
For instance, if the string comma input would be "@", the final result would be then:

red@tomato
green@frog
white@snow

People, it would be even nicer if you post your answer as a code as well. Take into account that most of us are not reasonable coders :)

Thanks!
User avatar
kortezzzz
 
Posts: 763
Joined: Tue Mar 19, 2013 4:21 pm

Re: Append array indexes in ruby?

Postby KG_is_back » Wed Sep 28, 2016 3:32 pm

Code: Select all
output @array1.zip(@array2).map{|p| p.join(@comma||"")}



This one is a one-liner...
KG_is_back
 
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Append array indexes in ruby?

Postby kortezzzz » Wed Sep 28, 2016 7:34 pm

Thanks KG!
One liners are the best 8-)
User avatar
kortezzzz
 
Posts: 763
Joined: Tue Mar 19, 2013 4:21 pm


Return to General

Who is online

Users browsing this forum: No registered users and 46 guests