Skip to content

Commit cf8119a

Browse files
author
KatieAJenkins
committed
lucky numbers problem finished
1 parent 23b27eb commit cf8119a

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

reduce/core.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function productAll (array) {
3939
console.log(productAll(input1));
4040

4141

42-
var input2 = [[ 'Thundercats', '80s' ], //row
42+
var cartoonsObject = [[ 'Thundercats', '80s' ], //row
4343
[ 'The Powerpuff Girls', '90s' ], //row
4444
[ 'Sealab 2021', '00s' ]]; //row
4545
// var expected = { 'Thundercats': '80s',
@@ -52,28 +52,43 @@ function objectify (array) {
5252
//reach row is the element being passed in which is an array
5353
//console log to get the keys and values to populate our cartoonObject
5454
//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);
5758
// console.log(row);
5859
// console.log('row ', row[0]);
5960
// console.log('row2 ', row[1]);
6061
//build up cartoonObject object[key]
61-
cartoonObject[row[0]] = row[1];
62+
newCartoonObject[cartoonArray[0]] = cartoonArray[1];
6263
// console.log('cartoonObject ', cartoonObject);
6364

6465
// console.log('cartoon Object ', cartoonObject);
65-
return cartoonObject;
66+
return newCartoonObject;
6667
},
67-
{});
68+
{}); //empty object container for newCartoonObject
6869
}
6970

7071
//to get cartoonObject without console logging before return
71-
console.log(objectify(input2));
72+
console.log(objectify(cartoonsObject));
7273

74+
var input3 = [ 30, 48, 11, 5, 32 ];
75+
// var expected = 'Your lucky numbers are: 30, 48, 11, 5, and 32';
7376

77+
//define fortune string which is starting value 'Your lucky numbers are: '
7478
function luckyNumbers (array) {
7579
// 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);
7792

7893
module.exports = {
7994
sum: sum,

0 commit comments

Comments
 (0)