@@ -39,7 +39,7 @@ function productAll (array) {
39
39
console . log ( productAll ( input1 ) ) ;
40
40
41
41
42
- var input2 = [ [ 'Thundercats' , '80s' ] , //row
42
+ var cartoonsObject = [ [ 'Thundercats' , '80s' ] , //row
43
43
[ 'The Powerpuff Girls' , '90s' ] , //row
44
44
[ 'Sealab 2021' , '00s' ] ] ; //row
45
45
// var expected = { 'Thundercats': '80s',
@@ -52,28 +52,43 @@ function objectify (array) {
52
52
//reach row is the element being passed in which is an array
53
53
//console log to get the keys and values to populate our cartoonObject
54
54
//create cartoonObject
55
- //return cartoonObject starting variable
56
- return array . reduce ( function ( cartoonObject , row ) {
55
+ //return cartoonObject starting object/array/value
56
+ return array . reduce ( function ( newCartoonObject , cartoonArray ) {
57
+ // console.log('array ', array);
57
58
// console.log(row);
58
59
// console.log('row ', row[0]);
59
60
// console.log('row2 ', row[1]);
60
61
//build up cartoonObject object[key]
61
- cartoonObject [ row [ 0 ] ] = row [ 1 ] ;
62
+ newCartoonObject [ cartoonArray [ 0 ] ] = cartoonArray [ 1 ] ;
62
63
// console.log('cartoonObject ', cartoonObject);
63
64
64
65
// console.log('cartoon Object ', cartoonObject);
65
- return cartoonObject ;
66
+ return newCartoonObject ;
66
67
} ,
67
- { } ) ;
68
+ { } ) ; //empty object container for newCartoonObject
68
69
}
69
70
70
71
//to get cartoonObject without console logging before return
71
- console . log ( objectify ( input2 ) ) ;
72
+ console . log ( objectify ( cartoonsObject ) ) ;
72
73
74
+ var input3 = [ 30 , 48 , 11 , 5 , 32 ] ;
75
+ // var expected = 'Your lucky numbers are: 30, 48, 11, 5, and 32';
73
76
77
+ //define fortune string which is starting value 'Your lucky numbers are: '
74
78
function luckyNumbers ( array ) {
75
79
// your code here
76
- } ;
80
+ return array . reduce ( function ( previous , current , index , array ) {
81
+ // console.log('Your lucky numbers are: ' + element + element;
82
+ if ( index === array . length - 1 ) {
83
+ console . log ( previous + "and " + current ) ;
84
+ return previous + "and " + current ;
85
+ }
86
+ return previous + current + ", " ;
87
+ console . log ( previous + current ) ;
88
+ } , "Your lucky numbers are " ) ;
89
+ }
90
+
91
+ luckyNumbers ( input3 ) ;
77
92
78
93
module . exports = {
79
94
sum : sum ,
0 commit comments