min/max filtering (array)

For general discussion related FlowStone
User avatar
Nubeat7
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna
Contact:

Re: min/max filtering (array)

Post by Nubeat7 »

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
Contact:

Re: min/max filtering (array)

Post by Nubeat7 »

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
tester
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: min/max filtering (array)

Post by tester »

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 879 times
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
User avatar
Nubeat7
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna
Contact:

Re: min/max filtering (array)

Post by Nubeat7 »

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
Tronic
Posts: 539
Joined: Wed Dec 21, 2011 12:59 pm

Re: min/max filtering (array)

Post by Tronic »

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.
User avatar
Nubeat7
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna
Contact:

Re: min/max filtering (array)

Post by Nubeat7 »

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?
Tronic
Posts: 539
Joined: Wed Dec 21, 2011 12:59 pm

Re: min/max filtering (array)

Post by Tronic »

Yes work
sorry, mistake in my testing.
billv
Posts: 1165
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia
Contact:

Re: min/max filtering (array)

Post by billv »

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

...seems he saw similar issue...all good....thanks
Post Reply