Skip to content

Commit c4ab033

Browse files
authored
Create bird-watcher.js
1 parent 5d452c4 commit c4ab033

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

bird-watcher.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Calculates the total bird count.
3+
*
4+
* @param {number[]} birdsPerDay
5+
* @returns {number} total bird count
6+
*/
7+
export function totalBirdCount(birdsPerDay) {
8+
let count = 0;
9+
for (let i = 0; i < birdsPerDay.length; i++) {
10+
count+=birdsPerDay[i];
11+
};
12+
return count;
13+
}
14+
/**
15+
* Calculates the total number of birds seen in a specific week.
16+
*
17+
* @param {number[]} birdsPerDay
18+
* @param {number} week
19+
* @returns {number} birds counted in the given week
20+
*/
21+
export function birdsInWeek(birdsPerDay, week) {
22+
var startDay= (week -1) * 7;
23+
var endDay= startDay + 7;
24+
let count = 0;
25+
for (let i=startDay; i < endDay; i++) {
26+
count += birdsPerDay[i];
27+
}
28+
return count;
29+
}
30+
/**
31+
* Fixes the counting mistake by increasing the bird count
32+
* by one for every second day.
33+
*
34+
* @param {number[]} birdsPerDay
35+
* @returns {number[]} corrected bird count data
36+
*/
37+
export function fixBirdCountLog(birdsPerDay) {
38+
for (let i = 0; i < birdsPerDay.length; i+=2) {
39+
birdsPerDay[i] += 1;
40+
}
41+
return birdsPerDay;
42+
}

0 commit comments

Comments
 (0)