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
16 posts
• Page 1 of 2 • 1, 2
Ruby question - Filtering array duplications
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?
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?
-
kortezzzz - Posts: 763
- Joined: Tue Mar 19, 2013 4:21 pm
Re: Ruby question - Filtering array duplications
Try array.uniq
-
DaveyBoy - Posts: 131
- Joined: Wed May 11, 2016 9:18 pm
- Location: Leeds UK
Re: Ruby question - Filtering array duplications
Thanks Dave. I tried it but couldn't formulate it correctly. What exact syntax would you use to make it work in FS?
-
kortezzzz - Posts: 763
- Joined: Tue Mar 19, 2013 4:21 pm
Re: Ruby question - Filtering array duplications
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
["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
-
DaveyBoy - Posts: 131
- Joined: Wed May 11, 2016 9:18 pm
- Location: Leeds UK
Re: Ruby question - Filtering array duplications
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?
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?
-
kortezzzz - Posts: 763
- Joined: Tue Mar 19, 2013 4:21 pm
Re: Ruby question - Filtering array duplications
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?
Can you be more specific in what you are trying to achieve?
-
DaveyBoy - Posts: 131
- Joined: Wed May 11, 2016 9:18 pm
- Location: Leeds UK
Re: Ruby question - Filtering array duplications
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
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.
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.
-
kortezzzz - Posts: 763
- Joined: Tue Mar 19, 2013 4:21 pm
Re: Ruby question - Filtering array duplications
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
Found how to formulate it correctrlly in FS. An example schematic is attached.
Cheers!
Cheers!
- Attachments
-
- (filtering array duplicates).fsm
- (344 Bytes) Downloaded 818 times
-
kortezzzz - Posts: 763
- Joined: Tue Mar 19, 2013 4:21 pm
16 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 92 guests