-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbird-watcher.js
42 lines (42 loc) · 1018 Bytes
/
bird-watcher.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* Calculates the total bird count.
*
* @param {number[]} birdsPerDay
* @returns {number} total bird count
*/
export function totalBirdCount(birdsPerDay) {
let count = 0;
for (let i = 0; i < birdsPerDay.length; i++) {
count+=birdsPerDay[i];
};
return count;
}
/**
* Calculates the total number of birds seen in a specific week.
*
* @param {number[]} birdsPerDay
* @param {number} week
* @returns {number} birds counted in the given week
*/
export function birdsInWeek(birdsPerDay, week) {
var startDay= (week -1) * 7;
var endDay= startDay + 7;
let count = 0;
for (let i=startDay; i < endDay; i++) {
count += birdsPerDay[i];
}
return count;
}
/**
* Fixes the counting mistake by increasing the bird count
* by one for every second day.
*
* @param {number[]} birdsPerDay
* @returns {number[]} corrected bird count data
*/
export function fixBirdCountLog(birdsPerDay) {
for (let i = 0; i < birdsPerDay.length; i+=2) {
birdsPerDay[i] += 1;
}
return birdsPerDay;
}