Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 76 additions & 76 deletions data.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,117 +216,117 @@ var movies = [

var tweets = [
{
"user": "douglascalhoun",
"message": "that wizard overhauled this worm #techlife",
"createdAt": "2022-09-05T21:39:19.281Z",
"profilePhotoURL": "./assets/img/user-3.png"
'user': 'douglascalhoun',
'message': 'that wizard overhauled this worm #techlife',
'createdAt': '2022-09-05T21:39:19.281Z',
'profilePhotoURL': './assets/img/user-3.png'
},
{
"user": "douglascalhoun",
"message": "completely overhauled this security system #sxsw",
"createdAt": "2022-09-06T02:39:19.281Z",
"profilePhotoURL": "./assets/img/user-3.png"
'user': 'douglascalhoun',
'message': 'completely overhauled this security system #sxsw',
'createdAt': '2022-09-06T02:39:19.281Z',
'profilePhotoURL': './assets/img/user-3.png'
},
{
"user": "mracus",
"message": " formulated that cat ",
"createdAt": "2022-09-06T07:39:19.281Z",
"profilePhotoURL": "./assets/img/user-2.png"
'user': 'mracus',
'message': ' formulated that cat ',
'createdAt': '2022-09-06T07:39:19.281Z',
'profilePhotoURL': './assets/img/user-2.png'
},
{
"user": "douglascalhoun",
"message": "productively deployed my koolaid for real",
"createdAt": "2022-09-06T12:39:19.281Z",
"profilePhotoURL": "./assets/img/user-3.png"
'user': 'douglascalhoun',
'message': 'productively deployed my koolaid for real',
'createdAt': '2022-09-06T12:39:19.281Z',
'profilePhotoURL': './assets/img/user-3.png'
},
{
"user": "mracus",
"message": " delegated your belief system #burningman",
"createdAt": "2022-09-06T17:39:19.281Z",
"profilePhotoURL": "./assets/img/user-2.png"
'user': 'mracus',
'message': ' delegated your belief system #burningman',
'createdAt': '2022-09-06T17:39:19.281Z',
'profilePhotoURL': './assets/img/user-2.png'
},
{
"user": "shawndrost",
"message": "completely enjoyed the way of life ",
"createdAt": "2022-09-06T22:39:19.281Z",
"profilePhotoURL": "./assets/img/user-0.png"
'user': 'shawndrost',
'message': 'completely enjoyed the way of life ',
'createdAt': '2022-09-06T22:39:19.281Z',
'profilePhotoURL': './assets/img/user-0.png'
},
{
"user": "shawndrost",
"message": " aided my worm ",
"createdAt": "2022-09-07T03:39:19.281Z",
"profilePhotoURL": "./assets/img/user-0.png"
'user': 'shawndrost',
'message': ' aided my worm ',
'createdAt': '2022-09-07T03:39:19.281Z',
'profilePhotoURL': './assets/img/user-0.png'
},
{
"user": "sharksforcheap",
"message": " experienced the bad decision but only i know how",
"createdAt": "2022-09-07T08:39:19.281Z",
"profilePhotoURL": "./assets/img/user-1.png"
'user': 'sharksforcheap',
'message': ' experienced the bad decision but only i know how',
'createdAt': '2022-09-07T08:39:19.281Z',
'profilePhotoURL': './assets/img/user-1.png'
},
{
"user": "douglascalhoun",
"message": "efficiently installed an entire koolaid #sf",
"createdAt": "2022-09-07T13:39:19.281Z",
"profilePhotoURL": "./assets/img/user-3.png"
'user': 'douglascalhoun',
'message': 'efficiently installed an entire koolaid #sf',
'createdAt': '2022-09-07T13:39:19.281Z',
'profilePhotoURL': './assets/img/user-3.png'
},
{
"user": "shawndrost",
"message": "the president automated the big system but only i know how",
"createdAt": "2022-09-07T18:39:19.281Z",
"profilePhotoURL": "./assets/img/user-0.png"
'user': 'shawndrost',
'message': 'the president automated the big system but only i know how',
'createdAt': '2022-09-07T18:39:19.281Z',
'profilePhotoURL': './assets/img/user-0.png'
},
{
"user": "douglascalhoun",
"message": "a seedy old man invented my city #yolo",
"createdAt": "2022-09-07T23:39:19.281Z",
"profilePhotoURL": "./assets/img/user-3.png"
'user': 'douglascalhoun',
'message': 'a seedy old man invented my city #yolo',
'createdAt': '2022-09-07T23:39:19.281Z',
'profilePhotoURL': './assets/img/user-3.png'
},
{
"user": "sharksforcheap",
"message": " interfaced the big potato ",
"createdAt": "2022-09-07T23:39:20.431Z",
"profilePhotoURL": "./assets/img/user-1.png"
'user': 'sharksforcheap',
'message': ' interfaced the big potato ',
'createdAt': '2022-09-07T23:39:20.431Z',
'profilePhotoURL': './assets/img/user-1.png'
},
{
"user": "mracus",
"message": "ask me how i systematized the big mind #techlife",
"createdAt": "2022-09-07T23:39:20.977Z",
"profilePhotoURL": "./assets/img/user-2.png"
'user': 'mracus',
'message': 'ask me how i systematized the big mind #techlife',
'createdAt': '2022-09-07T23:39:20.977Z',
'profilePhotoURL': './assets/img/user-2.png'
},
{
"user": "sharksforcheap",
"message": " debugged the big life #sf",
"createdAt": "2022-09-07T23:39:21.416Z",
"profilePhotoURL": "./assets/img/user-1.png"
'user': 'sharksforcheap',
'message': ' debugged the big life #sf',
'createdAt': '2022-09-07T23:39:21.416Z',
'profilePhotoURL': './assets/img/user-1.png'
},
{
"user": "shawndrost",
"message": " downloaded the money #burningman",
"createdAt": "2022-09-07T23:39:22.259Z",
"profilePhotoURL": "./assets/img/user-0.png"
'user': 'shawndrost',
'message': ' downloaded the money #burningman',
'createdAt': '2022-09-07T23:39:22.259Z',
'profilePhotoURL': './assets/img/user-0.png'
},
{
"user": "mracus",
"message": "just navigated your koolaid ",
"createdAt": "2022-09-07T23:39:23.233Z",
"profilePhotoURL": "./assets/img/user-2.png"
'user': 'mracus',
'message': 'just navigated your koolaid ',
'createdAt': '2022-09-07T23:39:23.233Z',
'profilePhotoURL': './assets/img/user-2.png'
},
{
"user": "mracus",
"message": "just enjoyed the big cloud for real",
"createdAt": "2022-09-07T23:39:24.329Z",
"profilePhotoURL": "./assets/img/user-2.png"
'user': 'mracus',
'message': 'just enjoyed the big cloud for real',
'createdAt': '2022-09-07T23:39:24.329Z',
'profilePhotoURL': './assets/img/user-2.png'
},
{
"user": "mracus",
"message": "last night i delegated the worm ",
"createdAt": "2022-09-07T23:39:24.645Z",
"profilePhotoURL": "./assets/img/user-2.png"
'user': 'mracus',
'message': 'last night i delegated the worm ',
'createdAt': '2022-09-07T23:39:24.645Z',
'profilePhotoURL': './assets/img/user-2.png'
},
{
"user": "shawndrost",
"message": " developed the cloud ",
"createdAt": "2022-09-07T23:39:25.694Z",
"profilePhotoURL": "./assets/img/user-0.png"
'user': 'shawndrost',
'message': ' developed the cloud ',
'createdAt': '2022-09-07T23:39:25.694Z',
'profilePhotoURL': './assets/img/user-0.png'
},
];
105 changes: 85 additions & 20 deletions practice.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
var moreFruits = function (fruits) {
var results = [];

_.each(fruits, function(fruit, index, collection) {
_.each(fruits, function (fruit, index, collection) {
results.push(fruit);
});

Expand All @@ -25,12 +25,24 @@ var moreFruits = function (fruits) {
// use _.each to traverse the number array and determine
// which are multiples of five.
var multiplesOfFive = function (numbers) {

var counter = 0;
_.each(numbers, function (number) {
if (number % 5 === 0) {
counter++;
}
});
return counter;
};

// use _.each to build an array containing only tweets belonging to a specified user.
var getUserTweets = function(tweets, user) {

var getUserTweets = function (tweets, user) {
var userTweets = [];
_.each(tweets, function (tweet) {
if (tweet.user === user) {
userTweets.push(tweet);
}
});
return userTweets;
};

/*
Expand All @@ -41,23 +53,31 @@ var getUserTweets = function(tweets, user) {

// use _.filter to return the fruits array with only the desired fruit.
var onlyOneFruit = function (fruits, targetFruit) {

return _.filter(fruits, function(fruit) {
return fruit === targetFruit;
});
};

// use _.filter to return the fruits array with only fruits
// starting with the letter 'P'.
var startsWith = function (fruits, letter) {

return _.filter(fruits, function(fruit) {
return fruit[0] === letter;
});
};

// return a filtered array containing only cookie-type desserts.
var cookiesOnly = function (desserts) {

return _.filter(desserts, function(dessert) {
return dessert.type === 'cookie';
});
};

// rebuild the getUserTweets function from above with _.filter instead
var filterUserTweets = function(tweets, user) {

var filterUserTweets = function (tweets, user) {
return _.filter(tweets, function(tweet) {
return tweet.user === user;
});
};

/*
Expand All @@ -69,20 +89,33 @@ var filterUserTweets = function(tweets, user) {
// given an array of strings, use _.map to return a new array containing all
// strings converted to uppercase letters.
var upperCaseFruits = function (fruits) {

return _.map(fruits, function(fruit) {
return fruit.toUpperCase();
});
};

// given an array of dessert objects, return a new array of objects
// that have a new "glutenFree" property, with a boolean value.
// TIP: Items that contain flour are not gluten-free.
var glutenFree = function (desserts) {

return _.map(desserts, function(dessert) {
if (!dessert['ingredients'].includes('flour')) {
dessert['glutenFree'] = true;
return dessert;

} else {
dessert['glutenFree'] = false;
return dessert;
}
});
};

// given an array of tweet objects, return a new array of strings
// containing only the message properties.
var allUserMessages = function(tweets) {

var allUserMessages = function (tweets) {
return _.map(tweets, function(tweet) {
return tweet.message;
});
};

// use _.map to return an array of items with their sale prices, with a new property
Expand All @@ -106,7 +139,13 @@ var allUserMessages = function(tweets) {

*/
var applyCoupon = function (groceries, coupon) {

return _.map(groceries, function(item) {
var price = Number(item.price.slice(1));
var salePrice = price - (price * coupon * 100) / 100;
var index = salePrice.toString().indexOf('.');
item['salePrice'] = '$' + salePrice.toString().slice(0, index + 3);
return item;
});
};

/*
Expand All @@ -117,13 +156,22 @@ var applyCoupon = function (groceries, coupon) {

// return the total price of all products.
var sumTotal = function (products) {

return _.reduce(products, function(memo, product) {
return memo += Number(product.price.slice(1));
}, 0);
};

// return an object consisting of dessert types and how many of each.
// exampleOutput: { dessertType: 3, dessertType2: 1 }
var dessertCategories = function (desserts) {

return _.reduce(desserts, function(memo, dessert) {
if (memo[dessert.type] === undefined) {
memo[dessert.type] = 1;
} else {
memo[dessert.type] ++;
}
return memo;
}, {});
};

// return an object with the proper count of all user messages
Expand All @@ -137,20 +185,37 @@ var dessertCategories = function (desserts) {
"sharksforcheap": 3
}
*/
var countMessagesPerUser = function(tweets) {

var countMessagesPerUser = function (tweets) {
return _.reduce(tweets, function(memo, tweet) {
if (memo[tweet.user] === undefined) {
memo[tweet.user] = 1;
} else {
memo[tweet.user]++;
}
return memo;
}, {});
};

// given an array of movie data objects,return an array containing
// movies that came out between 1990 and 2000.
// TIP: use an array as your accumulator - don't push to an external array!
var ninetiesKid = function (movies) {

return _.reduce(movies, function(memo, movie) {
if (movie.releaseYear >= 1990 && movie.releaseYear <= 2000) {
memo.push(movie.title);
}
return memo;
}, []);
};

// return an boolean stating if there exists a movie with a shorter
// runtime than your time limit.
// timeLimit is an integer representing a number of minutes.
var movieNight = function (movies, timeLimit) {

return _.reduce(movies, function(memo, movie) {
if (movie.runtime < timeLimit) {
memo = true;
}
return memo;
}, false);
};
Loading