Js two-dimensional array

var arr = [
            { date: "2018-10-31", a: 1, b: 2, c: 3, e: 8 },
            { date: "2018-10-27", a: 3, b: 4, c: 5, e: 7 },
            { date: "2018-10-29", a: 3, b: 4, c: 5, e: 9 },
            { date: "2018-10-30", a: 4, b: 5, c: 6, e: 0 },
            { date: "2018-10-28", a: 7, b: 8, c: 10, e: 1 },
        ];
        // 
        // : 
        //  
        // date
        // table t;  t = c + e;  t = t - b



kindhearted people help to see how to write, feel that the array is so confused!

Oct.07,2021

    var arr = [
        { date: '2018-10-31', a: 1, b: 2, c: 3, e: 8 },
        { date: '2018-10-27', a: 3, b: 4, c: 5, e: 7 },
        { date: '2018-10-29', a: 3, b: 4, c: 5, e: 9 },
        { date: '2018-10-30', a: 4, b: 5, c: 6, e: 0 },
        { date: '2018-10-28', a: 7, b: 8, c: 10, e: 1 },
    ];
    // 
    arr.sort(function(a,b){
        return Date.parse(new Date(a.date)) < Date.parse(new Date(b.date))
    })
    

clipboard.png


clipboard.png

you didn't say what to do with other operations. Don't panic.

probably wrote it down, but didn't check it carefully

const getTimeNum = (dateStr) => {
  let dateArr = dateStr.split('-').map((t, i) => {
    t = +t;
    if (i === 1) t--; //  0 ~ 11
    return t;
  });
  return new Date().setFullYear(...dateArr);
}
// 
arr.sort((a, b) => {
  return getTimeNum(b.date) - getTimeNum(a.date);
})
// t
let maxNum = 0; // 
arr = arr.reduce((prev, cur) => {
  for (key in prev[0]) {
    if (key != 'date') {
      maxNum = Math.max(maxNum, cur[key]);
      prev[0][key] += cur[key];
    }
  }
  prev.push({
    ...cur,
    t: prev.length > 1 ? (prev[prev.length - 1].t - cur.b) : (cur.c + cur.e) // t
  });
  return prev;
}, [{date: '', a: 0, b: 0, c: 0, e: 0}]); // arr[0] 

see if it can help you: `var arr = [

]
{ date: '2018-10-31', a: 1, b: 2, c: 3, e: 8 },
{ date: '2018-10-27', a: 3, b: 4, c: 5, e: 7 },
{ date: '2018-10-29', a: 3, b: 4, c: 5, e: 9 },
{ date: '2018-10-30', a: 4, b: 5, c: 6, e: 0 },
{ date: '2018-10-28', a: 7, b: 8, c: 10, e: 1 },

];
let t = 0;
for (var i = 0; I

if (i == 0) {
    t = arr[i].c + arr[i].e;
} else {
    t = t - arr[i].b;
}

}

console.log (t); `

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b33378-e3c6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b33378-e3c6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?