Js deals with data algorithm problems

var a = [

]
{x: 1, y: 2, z: 3},
{x: 1, y: 2, z: 4},
{x: 1, y: 1, z: 0},
{x: 1, y: 2, z: 3}

]
when the values of y in array an are the same as the sum of the same value z

example: a has three y with the same z sum of 3"4"3? Find the optimal solution

Nov.19,2021

var a = [
{x: 1, y: 2, z: 3},
{x: 1, y: 2, z: 4},
{x: 1, y: 1, z: 1},
{x: 1, y: 2, z: 3},
{x: 1, y: 1, z: 4},
]
for(var i=0,arr=[],cache=[],val=0;i<a.length;iPP){
  var y= a[i].y, 
   idx = cache.indexOf(y);
  (idx==-1)?(cache.push(y),arr.push({k:y,val:a[i].z})):(arr[idx].val+=a[i].z);
}
console.log(arr);
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-1b38054-4ed45.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-1b38054-4ed45.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?