Getting Max/Min value out of an Array?

264 views
Skip to first unread message

Walter Francis

unread,
May 21, 2013, 12:43:29 PM5/21/13
to tas...@googlegroups.com
I keep thinking I must be obtuse here, as it seems like I should be able to do this but I'm not figuring out anything.

I have an array of 480 values, I want to find the Max and Min value.  Is there an easy way to do this?  What I started with at first was copying one array into another, such as %tempArr = %arr(#?) and was hoping to  just grab the first and last elements, but that doesn't seem to work, I just get a variable with the comma separated data.  

So, is there a direct way to get Max/Min, alternatively, is there a way to copy the array and grab first/last?  

Thanks!

Pent

unread,
May 21, 2013, 2:28:29 PM5/21/13
to Tasker
> So, is there a direct way to get Max/Min, alternatively, is there a way to
> copy the array and grab first/last?

You lost me a bit. How will copying the array then getting first/last
help ?
You would need to copy then sort. Or just sort, if you don't care
about
the original order.

Best way is probably to sort with a JavaScriptlet (was in a thread
somewhere)
then use %arr(#<) and %arr(#>) (last/first element)

Pent

Walter Francis

unread,
May 21, 2013, 3:40:08 PM5/21/13
to tas...@googlegroups.com
Pent,

I was thinking I could copy it into another array (so I don't mess with the original, I don't want the real data rearranged) and then sort the copy and do < >, but I thought for some reason I could sort the new array with %array(#?) but I'm apparently confused, I'll look up the javascript and see how that works.  :)

I'm slowly piecing together a weather station..  No weather apps seem to do exactly what I want so I'm making it in Tasker.  Working on the barometric pressure piece right now.  :)

Thanks!

Rich D

unread,
May 21, 2013, 4:24:47 PM5/21/13
to tas...@googlegroups.com

This javascript will do an alphanumeric sort

var arr = [];
arr = testsort.split( "," );
arr.sort(function (a, b) { return a.toLowerCase().localeCompare(b.toLowerCase()); });

It will take the local variable %testsort That contains a comma separated list and return the sorted comma separated list in the local array %arr

So you'll just need to do a variable set %testsort = %Yourarray(:) first and this will save your original array and give you a sorted  array in %arr

Rich..

Rich D

unread,
May 21, 2013, 4:28:02 PM5/21/13
to tas...@googlegroups.com


Oooops..

** EDIT **

> It will take the local variable %testsort That contains a comma separated list and return the sorted  local array %arr

Reply all
Reply to author
Forward
0 new messages