Last active
September 17, 2022 13:41
-
-
Save vlcanunal/7813a3b15640eb124a73ec507824eb34 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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