Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sorting of beacons in example apps #187

Open
ghost opened this issue Feb 15, 2016 · 0 comments
Open

Add sorting of beacons in example apps #187

ghost opened this issue Feb 15, 2016 · 0 comments

Comments

@ghost
Copy link

ghost commented Feb 15, 2016

In examples apps that display lists of beacons and BLE devices, the list can be sorted, by RSSI, distance etc.

Sorting function from Alexis:

function sortBeaconsByProximity(beacons) {
    var beaconKeyRssiArray = [];
    var sortedBeacons = {};

    for (var key in beacons) {
        beaconKeyRssiArray.push([beacons[key], key, beacons[key].rssi]);
    }

    beaconKeyRssiArray.sort(function(a, b) {
        return b[2] - a[2];
    });

    for (var i = 0; i < beaconKeyRssiArray.length; i++) {
        sortedBeacons[beaconKeyRssiArray[i][1]] = beaconKeyRssiArray[i][0];
    }

    return sortedBeacons;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants