Skip to content

Commit

Permalink
make sorting more comparable across browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua B. Smith committed Oct 19, 2016
1 parent 4740869 commit 812bafa
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions public/js/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,20 @@ $(document).ready(function () {
return accumulator;
}

function sortIdxComparator(a, b) {
if (a < b) {
return -1;
}

if (a > b) {
return 1;
}

if (a === b) {
return 0;
}
}

function loadConsumptionPreferences(data) {
var cpsect = $(".output-summary--consumption-behaviors--section")
var behaviors = $(".output-summary--consumption-behaviors--section")
Expand Down Expand Up @@ -564,13 +578,13 @@ $(document).ready(function () {
behaviors.html("");
behaviors.append("<h4 class=\"base--h4\">You are likely to______ </h4>");
behaviors.append("<div class=\"output-summary--likely-behaviors\">");
likelycps.sort(function(l,r) { return l.idx > r.idx; }).reduce(addIfAllowedReducer,[]).slice(0,3).map(function(item) {
likelycps.sort(sortIdxComparator).reduce(addIfAllowedReducer,[]).slice(0,3).map(function(item) {
behaviors.append("<div class=\"output-summary--behavior output-summary--behavior_POSITIVE\"><i class=\"icon icon-likely\"></i>" + item.name + "</div>\n");
});
behaviors.append("</div>");
behaviors.append("<h4 class=\"base--h4\">You are unlikely to______ </h4>");
behaviors.append("<div class=\"output-summary--unlikely-behaviors\">");
unlikelycps.sort(function(l,r) { return l.idx > r.idx; }).reduce(addIfAllowedReducer,[]).slice(0,3).map(function(item) {
unlikelycps.sort(sortIdxComparator).reduce(addIfAllowedReducer,[]).slice(0,3).map(function(item) {
behaviors.append("<div class=\"output-summary--behavior output-summary--behavior_NEGATIVE\"><i class=\"icon icon-not-likely\"></i>" + item.name + "</div>\n");
});
behaviors.append("</div>");
Expand Down

0 comments on commit 812bafa

Please sign in to comment.