@@ -12,13 +12,55 @@ function sum (array) {
12
12
13
13
console . log ( sum ( input ) ) ;
14
14
15
+ var input1 = [ [ 1 , 2 , 3 ] , //row
16
+ [ 4 , 5 ] ,
17
+ [ 6 ] ] ;
18
+
19
+ //output = 720
20
+
15
21
function productAll ( array ) {
16
22
// your code here
17
- } ;
23
+ return array . reduce ( function ( product , row ) {
24
+ console . log ( 'product ' , product ) ;
25
+ console . log ( 'row ' , row ) ;
26
+ //product starts at 1. will hold all the results of reduce on each row
27
+ //
28
+ product *= row . reduce ( function ( prev , current ) {
29
+ console . log ( 'prev ' , prev ) ;
30
+ console . log ( 'current ' , current ) ;
31
+ console . log ( prev * current ) ;
32
+ return prev * current ;
33
+ } ) ;
34
+ console . log ( product ) ;
35
+ return product ;
36
+ } , 1 ) ;
37
+ }
38
+
39
+ console . log ( productAll ( input1 ) ) ;
40
+
41
+
42
+ var input2 = [ [ 'Thundercats' , '80s' ] ,
43
+ [ 'The Powerpuff Girls' , '90s' ] ,
44
+ [ 'Sealab 2021' , '00s' ] ] ;
45
+ // var expected = { 'Thundercats': '80s',
46
+ // 'The Powerpuff Girls': '90s',
47
+ // 'Sealab 2021': '00s' };
18
48
19
49
function objectify ( array ) {
20
50
// your code here
21
- } ;
51
+ //cartoonObject is our accumulator object, so also need {}
52
+ //reach row is the element being passed in which is an array
53
+ return array . reduce ( function ( cartoonObject , row ) {
54
+
55
+ console . log ( 'row ' , row [ 0 ] ) ;
56
+ // console.log(newObject);
57
+
58
+ console . log ( cartoonObject ) ;
59
+ return cartoonObject ;
60
+ } , { } ) ;
61
+ }
62
+
63
+ objectify ( input2 ) ;
22
64
23
65
function luckyNumbers ( array ) {
24
66
// your code here
0 commit comments