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
empty-line indexes and items removal - ruby
3 posts
• Page 1 of 1
empty-line indexes and items removal - ruby
Two arrays scenario.
array 1 contains some empty lines:
a1
b1
[empty line]
[empty line]
e1
f1
array 2 is full.
a2
b2
c2
d2
e2
f2
both arrays are identical in size.
in ruby:
1) How to get a list of indexes of empty lines in array 1?
2) How to use the list of (these) indexes, to remove corresponding lines in array 2?
p.s.: still on FS 3.8.
array 1 contains some empty lines:
a1
b1
[empty line]
[empty line]
e1
f1
array 2 is full.
a2
b2
c2
d2
e2
f2
both arrays are identical in size.
in ruby:
1) How to get a list of indexes of empty lines in array 1?
2) How to use the list of (these) indexes, to remove corresponding lines in array 2?
p.s.: still on FS 3.8.
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Feel free to donate. Thank you for your contribution.
- tester
- Posts: 1786
- Joined: Wed Jan 18, 2012 10:52 pm
- Location: Poland, internet
Re: empty-line indexes and items removal - ruby
There is no such thing as an empty line in an array. Every entry in an array is an object. But you could use the nil-object.
Then this is doing what you ask for:
Then this is doing what you ask for:
- Code: Select all
a1 = 1, 2, nil, nil, 5, 6
a2 = "a", "b", "c", "d", "e", "f"
a1.each.with_index {|v, i| if v == nil then a2[i] = nil end}
a2.compact!
#a2 is now ["a", "b", "e", "f"]
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: empty-line indexes and items removal - ruby
Thanks, will check it.
BTW, nil or empty - depends on layer of reference. On GUI layer it's empty line, for programming language - it's nil.
BTW, nil or empty - depends on layer of reference. On GUI layer it's empty line, for programming language - it's nil.
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Feel free to donate. Thank you for your contribution.
- tester
- Posts: 1786
- Joined: Wed Jan 18, 2012 10:52 pm
- Location: Poland, internet
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: Google [Bot] and 60 guests