sorting - JavaScript array sort not working in default Android browser -
i have problem function listed below. on pc code working perfectly, , on chrome on mobile phone too. however, when run code in default android browser result first 4 elements of sorted array not supposed be;
- element 1: 0
- element 2: 128
- element 3: 256
- element 4: 384
now wondering why case, until array sorted values gathered fine, after that, incorrect...
according link should compatible default android browser: https://developer.mozilla.org/en-us/docs/web/javascript/reference/global_objects/array/sort#browser_compatibility
function sendweekprogram() { //get info send var weekprogramdata; //check if week program enabled if($("#vacationmode").prop('checked') === false) { weekprogramdata = '<week_program state="on">'; }else { weekprogramdata = '<week_program state="off">'; } //for each day switches for(i = 0; < 7; i++) { //set day name switch(i) { case 0: dayname = "monday"; break; case 1: dayname = "tuesday"; break; case 2: dayname = "wednesday"; break; case 3: dayname = "thursday"; break; case 4: dayname = "friday"; break; case 5: dayname = "saturday"; break; case 6: dayname = "sunday"; break; } //add day query weekprogramdata = weekprogramdata + '<day name="' + dayname + '">'; //create array var arrayswitches = []; //put day switches in array for(j = 0; j < 5; j++) { //check if switch on or off if(($("#dayswitch" + dayname + (j + 1)).hasclass("dayoverviewtextactive") === false) || ($("#nightswitch" + dayname + (j + 1)).hasclass("dayoverviewtextactive") === false)) { arrayswitches[j] = {type: 'day', state: 'off', value: parseint($("#dayswitch" + dayname + (j + 1)).text().replace(":", ""))}; }else { arrayswitches[j] = {type: 'day', state: 'on', value: parseint($("#dayswitch" + dayname + (j + 1)).text().replace(":", ""))}; } } //put night switches in array for(j = 5; j < 10; j++) { //check if switch on or off if(($("#dayswitch" + dayname + (j-4)).hasclass("dayoverviewtextactive") === false) || ($("#nightswitch" + dayname + (j-4)).hasclass("dayoverviewtextactive") === false)) { arrayswitches[j] = {type: 'night', state: 'off', value: parseint($("#nightswitch" + dayname + (j-4)).text().replace(":", ""))}; }else { arrayswitches[j] = {type: 'night', state: 'on', value: parseint($("#nightswitch" + dayname + (j-4)).text().replace(":", ""))}; } } //sort array arrayswitches.sort(function(a, b) { return a.value - b.value; }); //for each element in array, add weekprogramdata for(k = 0; k < 10; k++) { //add leading zeroes arrayvalue = arrayswitches[k].value.tostring(); while(arrayvalue.length < 4) { arrayvalue = "0" + arrayvalue; } //first convert integer time time = arrayvalue.substr(0,2) + ':' + arrayvalue.substr(2); //add value weekprogram weekprogramdata = weekprogramdata + '<switch type="' + arrayswitches[k].type + '" state="' + arrayswitches[k].state + '">' + time + '</switch>'; } //add closing tag of day weekprogramdata = weekprogramdata + '</day>'; } //add closing tag of week program weekprogramdata = weekprogramdata + '</week_program>'; //send info putinfo("weekprogram", weekprogramdata); }
Comments
Post a Comment