0
function SUMMARIZE_TOGGL_ENTRIES(proj, desc, time, taskDates, uID) {
  if (!desc.map || !time.map || !taskDates.map || !proj.map) {
      return 'INPUT HAS TO BE MAP';
  }
  if (desc.length != time.length || time.length != taskDates.length || proj.length != taskDates.length) {
      return 'WRONG INPUT ARRAYS LEN';
  }
  var resObj = {'NO_DESCRIPTION': '00:00:00'};
  var keys = [];
  var result = [];
  for (var i = 1; i < desc.length; i++) {
      var tmpKey = createKey(proj[i], desc[i], uID[i]);
      console.log('tmpKey',tmpKey);
      if (resObj[tmpKey]) {
          resObj[tmpKey] = formatTime(timestrToSec(resObj[tmpKey]) + timestrToSec(time[i]));
      } else {
          resObj[tmpKey] = formatTime(timestrToSec(time[i]));
      }
  }
  keys = Object.keys(resObj);

  var b=0;
  for (b; b < keys.length; b++) {
      var tmp = [];
      var key = keys[b].split('__')[1];
      console.log('keys',keys[b].split('__'));
      tmp.push(keys[b].split('__')[0]);
      tmp.push(key);
      tmp.push(resObj[keys[b]]);
      tmp.push(taskLastDate(keys[b], desc, taskDates, proj, uID))
      tmp.push(keys[b].split('__')[2]);
    if(tmp[3] != '01-01-1991 01:01:01' && tmp[3] != ''){
      result.push(tmp);
    }

  }
  return result.sort(function (a,b){
    var ad = new Date(a[3].split(' ')[0].replace(/-/g,'.'));
    var bd = new Date(b[3].split(' ')[0].replace(/-/g,'.'));

    if (ad > bd) {
      return 1;
    }
    if (ad < bd) {
      return -1;
    }
    return 0;
  });
}

as you can see I'm trying to return a sorted array of arrays. But it don't returns the same array. If i lunch this func on my PC it works. so what's the problem? Does anyone have an idea?

result image

1
  • 1. See minimal reproducible example: You're not providing variables description or sample data. 2. why replace(/-/g,'.')? Date.parse() is implementation dependent. Try removing both ad and bd and use a>b lexicographic comparison. Commented Jan 14, 2020 at 9:32

1 Answer 1

1

Seems like your sort function will always return 0. Change to

return result.sort(function (a,b){
var ad = new Date(a[3].split(' ')[0].replace(/-/g,'.'));
var bd = new Date(b[3].split(' ')[0].replace(/-/g,'.'));

if (ad > bd) {
  return 1;
} else if (ad < bd) {
  return -1;
} else {
  return 0;
}
});

and see if that works?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.