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

min/max filtering (array)

For general discussion related FlowStone

Re: min/max filtering (array)

Postby Nubeat7 » Sat Nov 09, 2013 11:12 am

Tronic wrote:array = [-1,0.0,90,50,100,150,200]

min = 0.0 ;
max = 100 ;

(array.map {|v| (min..max) === v ? v : nil }).compact


smart! already met the "case equality operator" few times, but never knew where/how to use..
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Re: min/max filtering (array)

Postby Nubeat7 » Sat Nov 09, 2013 11:22 am

billv wrote:I still can't get a result from this...
Code: Select all
def event i,v
  if i == 0 then
    minVal = 0.5
    maxVal = 1
   a = @txt.map{|item|item*maxVal-minVal+minVal}
   output 0,a
  end
end

watch this thread, trog explains the correct methode there..
viewtopic.php?f=3&t=1760
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Re: min/max filtering (array)

Postby tester » Sat Nov 09, 2013 12:07 pm

I see I opened a headache maker. :-)

Posting schematized ("green prims" compatible so to speak) idea provided by Tronic, in case someone with my (equall-or-less)skills looks for such thing. :D

Seems to work fine, and looks elegant. Thanks!
Attachments
in-min-max-range.fsm
(449 Bytes) Downloaded 779 times
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
tester
 
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: min/max filtering (array)

Postby Nubeat7 » Sat Nov 09, 2013 12:21 pm

i think a combination of tronics version and mine would be the shortest and fastest
Code: Select all
output @yourarray.keep_if{|x|(min..max) === x}


i`m @ work, so not tested
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Re: min/max filtering (array)

Postby Tronic » Sat Nov 09, 2013 1:23 pm

Nubeat7 wrote:i think a combination of tronics version and mine would be the shortest and fastest
Code: Select all
output @yourarray.keep_if{|x|(min..max) === x}


i`m @ work, so not tested


This break the result of array if the next value not match the min/max range.
Tronic
 
Posts: 539
Joined: Wed Dec 21, 2011 12:59 pm

Re: min/max filtering (array)

Postby Nubeat7 » Sat Nov 09, 2013 1:46 pm

Tronic wrote:
Nubeat7 wrote:i think a combination of tronics version and mine would be the shortest and fastest
Code: Select all
output @yourarray.keep_if{|x|(min..max) === x}


i`m @ work, so not tested


This break the result of array if the next value not match the min/max range.


hmm strange i tried it here:
http://www.compileonline.com/execute_ruby_online.php

Code: Select all
array = [5,1,3,4,1,6,7,8,9]
array.keep_if{|x|(2..7) === x}
puts array;


and it puts:
5
3
4
6
7

so it shoul be right?
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Re: min/max filtering (array)

Postby Tronic » Sat Nov 09, 2013 2:19 pm

Yes work
sorry, mistake in my testing.
Tronic
 
Posts: 539
Joined: Wed Dec 21, 2011 12:59 pm

Re: min/max filtering (array)

Postby billv » Sat Nov 09, 2013 2:26 pm

Nubeat7 wrote:watch this thread, trog explains the correct methode there..

...seems he saw similar issue...all good....thanks
billv
 
Posts: 1157
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia

Previous

Return to General

Who is online

Users browsing this forum: No registered users and 44 guests