-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapple_orange.js
More file actions
34 lines (28 loc) · 754 Bytes
/
apple_orange.js
File metadata and controls
34 lines (28 loc) · 754 Bytes
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
/*
* Complete the 'countApplesAndOranges' function below.
*
* The function accepts following parameters:
* 1. INTEGER s
* 2. INTEGER t
* 3. INTEGER a
* 4. INTEGER b
* 5. INTEGER_ARRAY apples
* 6. INTEGER_ARRAY oranges
*/
function countApplesAndOranges(s, t, a, b, apples, oranges) {
const isBetween = (n) => {
if (n >= s && n <= t) {
return 1;
}
return 0;
}
const applesCount = apples.reduce((acc, apple) => {
return acc + isBetween(a + apple);
}, 0);
console.log(applesCount, '\n');
const orangesCount = oranges.reduce((acc, orange) => {
return acc + isBetween(b + orange);
}, 0);
console.log(orangesCount);
}
console.log(countApplesAndOranges())