Skip to content

Instantly share code, notes, and snippets.

@vlcanunal
Last active September 17, 2022 13:41
Show Gist options
  • Save vlcanunal/7813a3b15640eb124a73ec507824eb34 to your computer and use it in GitHub Desktop.
Save vlcanunal/7813a3b15640eb124a73ec507824eb34 to your computer and use it in GitHub Desktop.
var parseCityData = function (cityList, ts) {
var totalCityList = { time: "", cityData: [] };
(cityList || []).forEach((element) => {
hasCityExisted = totalCityList.cityData.some(function (item) {
return item.cityId === element.CITYID;
});
// If it doesnt exist in our list, we are adding the data to our list.
if (!hasCityExisted) {
totalCityList.cityData.push({
cityId: element.CITYID,
totalOrderCount: element.TOTALCOUNT,
totalPriceSum: element.TOTALPRICE,
});
// If the current city exists in our list, we are updating it's information.
} else {
totalCityList.cityData.forEach(function (item) {
if (item.cityId === element.CITYID) {
item.totalOrderCount += element.TOTALCOUNT;
item.totalPriceSum += element.TOTALPRICE;
}
});
}
});
totalCityList.time = ts;
return totalCityList;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment