-
Notifications
You must be signed in to change notification settings - Fork 0
/
challeng1.js
executable file
·44 lines (28 loc) · 1.11 KB
/
challeng1.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
43
44
const checkDogsAges = function (dogsKate, dogsjulia){
const dogsjuliaCorrected = dogsjulia.slice();
dogsjuliaCorrected.splice(0,1);
dogsjuliaCorrected.splice(-2);
console.log(dogsjuliaCorrected);
//we have to concat them then forEach
const dogs = dogsKate.concat(dogsjulia);
console.log(dogs);
dogs.forEach(function(age,i){
if(age >= 3){
console.log(`dog number ${i+1} and is an adult and is ${age} years old!`);
} else{
console.log(`dog number ${i+1} and is still a pupy 🐕🦺`);
}
})
}
checkDogsAges(['3','5','2','12','7'], ['4','1','15','8','3'])
const calcAverageHumanAge = (dogs) => {
dogs.map((dogAge) => (dogAge <= 2 ? 2 * dogAge : 16 + dogAge * 4))
.filter((age) => age >= 18)
.reduce((acc, curr,i, arr) => {
acc + curr / arr.length;
},0)
// return average;
}
const avg1 = calcAverageHumanAge([5, 2 , 4 , 1 , 15 , 8 , 3]);
const avg2 = calcAverageHumanAge([16, 6 , 10 , 5 , 6 , 1 , 4]);
console.log(avg1,avg2);