Page 2 of 2
Re: min/max filtering (array)
Posted: Sat Nov 09, 2013 11:12 am
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..
Re: min/max filtering (array)
Posted: Sat Nov 09, 2013 11:22 am
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
Re: min/max filtering (array)
Posted: Sat Nov 09, 2013 12:07 pm
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.
Seems to work fine, and looks elegant. Thanks!
Re: min/max filtering (array)
Posted: Sat Nov 09, 2013 12:21 pm
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
Re: min/max filtering (array)
Posted: Sat Nov 09, 2013 1:23 pm
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.
Re: min/max filtering (array)
Posted: Sat Nov 09, 2013 1:46 pm
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.phpCode: 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?
Re: min/max filtering (array)
Posted: Sat Nov 09, 2013 2:19 pm
by Tronic
Yes work
sorry, mistake in my testing.
Re: min/max filtering (array)
Posted: Sat Nov 09, 2013 2:26 pm
by billv
Nubeat7 wrote:watch this thread, trog explains the correct methode there..
...seems he saw similar issue...all good....thanks