1+ // Coding Challenge 1
2+
3+ /*
4+ Julia and Kate are doing a study on dogs.So each of them asked 5 dog owners
5+ about their dog's age, and stored the data into an array (one array for each). For;
6+ now, they are just interested in knowing whether a dog is an adult or a puppy.
7+ A dog is an adult if it is at least 3 years old, and it's a puppy if it's less than 3 years;
8+ old.
9+ Your tasks:
10+ Create a function 'checkDogs', which accepts 2 arrays of dog's ages
11+ ('dogsJulia' and 'dogsKate'), and does the following things:
12+ 1. Julia found out that the owners of the first and the last two dogs actually have;
13+ cats, not dogs! So create a shallow copy of Julia's array, and remove the cat
14+ ages from that copied array(because it's a bad practice to mutate function
15+ parameters);
16+ 2. Create an array with both Julia's (corrected) and Kate's data;
17+ 3. For each remaining dog, log to the console whether it's an adult ("Dog number 1
18+ is an adult, and is 5 years old") or a puppy ("Dog number 2 is still a puppy
19+ 🐶 ");
20+ 4. Run the function for both test datasets
21+ Test data:
22+ § Data 1: Julia's data [3, 5, 2, 12, 7], Kate's data[4, 1, 15, 8, 3]
23+ § Data 2: Julia's data [9, 16, 6, 8, 3], Kate's data[10, 5, 6, 1, 4];
24+ Hints: Use tools from all lectures in this section so far 😉
25+ GOOD LUCK 😀
26+ */
27+
28+ const dogsJulia1 = [ 3 , 5 , 2 , 12 , 7 ] ;
29+ const dogsKate1 = [ 4 , 1 , 15 , 8 , 3 ] ;
30+ const dogsJulia2 = [ 9 , 16 , 6 , 8 , 3 ] ;
31+ const dogsKate2 = [ 10 , 5 , 6 , 1 , 4 ] ;
32+
33+ const checkDogs = ( dogsJulia , dogsKate ) =>
34+ {
35+ const dogsJuliaCorr = dogsJulia . slice ( 1 , - 2 ) ;
36+ //console.log(`Dogs Julia: ${ dogsJulia }`);
37+ //console.log(`Dogs Julia (Cats Removed): ${ dogsJuliaReal }`);
38+
39+ const allDogs = dogsJuliaCorr . concat ( dogsKate ) ;
40+
41+ let msg = '' ;
42+ allDogs . forEach ( ( dog , i , arr ) =>
43+ {
44+ const type = ( dog < 3 ) ? `still a puppy 🐶` : `an adult, and is ${ dog } years old` ;
45+
46+ msg = msg . concat ( `Dog number ${ i + 1 } is ${ type } \n` ) ;
47+ } ) ;
48+ console . log ( msg ) ;
49+ } ;
50+
51+ console . log ( '----- TEST 1 -----' ) ;
52+ checkDogs ( dogsJulia1 , dogsKate1 ) ;
53+
54+ console . log ( '----- TEST 2 -----' ) ;
55+ checkDogs ( dogsJulia2 , dogsKate2 ) ;
0 commit comments