Sort of imp.scanwifinetworks()

Hi
I’m wondering if anybody can help on sorting the results of an imp.scanwifnetworks().
I realize I’ve got the basic idea and found the description arr.sort(@(a,b) a <=> b); but it I’m missing something in getting the squirrel syntax right.
So here is what I have so far

local scanResults = imp.scanwifinetworks(); //log as recorded foreach (idx,val in scanResults) { server.log("SSID="+ scanResults[idx].ssid +" Ch="+scanResults[idx].channel + " rssi="+scanResults[idx].rssi +" Open=" +scanResults[idx].open ); }

Now for the sort based on RSSI strength - probably have to implement a bubble sort
something like this Python example.
Is there a short cut using the array.sort(@…) seems to simplisitc - but thought I would ask
scanResults.sort(@(scanResults[idx].rssi,scanResults[idx-1].rssi) a < b);
Many thanks for any insights

I just went through this myself :slight_smile:

scanResults.sort(function(a,b) { return a.rssi <=> b.rssi; });

Wonderful it worked!. Reading the manual it looked too simple, didn’t explain it would actually switch records, and I didn’t get the right syntax. Thankyou thankyou.

No problem! It took me a while to figure out what was going on with the sort function.

Someday we’ll find time to write better Squirrel documentation!