File tree 1 file changed +42
-0
lines changed 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments