Get a monthly average

Asked 2 years ago, Updated 2 years ago, 51 views

Hi, everyone.

I'm implementing the dashboard function using the Firebase database.

Bring each number and sprinkle it on Monday, Tuesday, Wednesday, Thursday, Friday and Saturday.

For example, if you get a value of = 50 on Monday.

I'd like to get the average value for Monday of the month. The number of Mondays isn't the same

It's hard to get the hang of it TT

If you know how to do it or have any ideas, please help me TT!

jquery javascript firebase

2022-09-21 21:53

2 Answers

Assume that the object means one month
var month = { mon:[], tue:[], wed:[], thu:[], fri:[], sat:[], sun:[] }
Organize objects in this way (I think you can use a two-dimensional array)
After pushing the values sequentially to the corresponding day of the week,
It would be good to find the number of days of the week based on the length value of the array


2022-09-21 21:53

If you use the getDay() function well, you will be able to see how many days a specific month has.

For example, you can find out what day a particular day is in the following ways:

function getWeekDay(sDate) {

    var yy = parseInt(sDate.substr(0, 4), 10);
    var mm = parseInt(sDate.substr(5, 2), 10);
    var dd = parseInt(sDate.substr(8), 10);
    var d = new Date(yy,mm - 1, dd);
    var weekday=new Array(7);
    weekday[0] = "Sunday";
    weekday[1] = "Monday";
    weekday[2] = "Tuesday";
    weekday[3] = "Wednesday";
    weekday[4] = "Thursday";
    weekday[5] = "Friday";
    weekday[6] = "Saturday";
    return weekday[d.getDay()];
}
 Execution result:
getWeekDay("2017-09-09")
"Saturday"


2022-09-21 21:53

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.