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

Ruby question - Filtering array duplications

For general discussion related FlowStone

Ruby question - Filtering array duplications

Postby kortezzzz » Thu May 16, 2019 11:29 am

Hi,

I tried few methods for this from the Ruby guide, but couldn't translate them with correct syntax in FS.

The example:
We have a given array:
dog
dog
frog
fish
cat
cat

We need to filter the duplications which are "dog" and "cat" and end up with
dog
frog
fish
cat

What would be the correct syntax for that?
User avatar
kortezzzz
 
Posts: 763
Joined: Tue Mar 19, 2013 4:21 pm

Re: Ruby question - Filtering array duplications

Postby DaveyBoy » Thu May 16, 2019 12:11 pm

Try array.uniq :)
User avatar
DaveyBoy
 
Posts: 131
Joined: Wed May 11, 2016 9:18 pm
Location: Leeds UK

Re: Ruby question - Filtering array duplications

Postby kortezzzz » Thu May 16, 2019 12:21 pm

Thanks Dave. I tried it but couldn't formulate it correctly. What exact syntax would you use to make it work in FS?
User avatar
kortezzzz
 
Posts: 763
Joined: Tue Mar 19, 2013 4:21 pm

Re: Ruby question - Filtering array duplications

Postby DaveyBoy » Thu May 16, 2019 1:30 pm

Like so:

["dog","dog","frog","fish","cat","cat"].uniq

Here's what I use for reference:
https://ruby-doc.org/core-1.9.3/Array.html#method-i-uniq

Hope this helps :)
User avatar
DaveyBoy
 
Posts: 131
Joined: Wed May 11, 2016 9:18 pm
Location: Leeds UK

Re: Ruby question - Filtering array duplications

Postby kortezzzz » Thu May 16, 2019 2:51 pm

Thanks,

But what if the array is not pre-determined (to "dog", cat", etc.)? Is there any kind of code that can recognize duplications in any given array?
User avatar
kortezzzz
 
Posts: 763
Joined: Tue Mar 19, 2013 4:21 pm

Re: Ruby question - Filtering array duplications

Postby DaveyBoy » Thu May 16, 2019 4:18 pm

Hmmm . . .I don't really understand what you're asking, uniq will remove any and all dupes as far as I know.

Can you be more specific in what you are trying to achieve?
User avatar
DaveyBoy
 
Posts: 131
Joined: Wed May 11, 2016 9:18 pm
Location: Leeds UK

Re: Ruby question - Filtering array duplications

Postby tulamide » Thu May 16, 2019 8:15 pm

DaveyBoy is right. The solution to what you described is Array #uniq, and it doesn't matter, what exactly is in the arrays, as long as the objects are comparable.
"There lies the dog buried" (German saying translated literally)
tulamide
 
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Ruby question - Filtering array duplications

Postby kortezzzz » Thu May 16, 2019 10:38 pm

Ok, so there is a method for this :)
But how I write it correctly inside FS Ruby module? Tried to formulate a code, but it didn't worked for me, so seems like I'm doing something wrong.
User avatar
kortezzzz
 
Posts: 763
Joined: Tue Mar 19, 2013 4:21 pm

Re: Ruby question - Filtering array duplications

Postby RJHollins » Fri May 17, 2019 1:29 am

kortezzzz wrote:Ok, so there is a method for this :)
But how I write it correctly inside FS Ruby module? Tried to formulate a code, but it didn't worked for me, so seems like I'm doing something wrong.

Post us an example of the code, so we can see what you are trying to do.
RJHollins
 
Posts: 1571
Joined: Thu Mar 08, 2012 7:58 pm

Re: Ruby question - Filtering array duplications

Postby kortezzzz » Fri May 17, 2019 10:42 pm

Found how to formulate it correctrlly in FS. An example schematic is attached.

Cheers!
Attachments
(filtering array duplicates).fsm
(344 Bytes) Downloaded 818 times
User avatar
kortezzzz
 
Posts: 763
Joined: Tue Mar 19, 2013 4:21 pm

Next

Return to General

Who is online

Users browsing this forum: Google [Bot] and 55 guests