Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

complete wbp #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
16 changes: 16 additions & 0 deletions callbacks/src/giveaway/giveaway.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,23 @@
*/

// YOUR CODE HERE:
function determineCouponRecipients(users, eligibilityCallback) {
const couponRecipients = [];
let count = 0;

for (const user of users) {
if (eligibilityCallback(user)) {
couponRecipients.push(user);
count++;

if (count === 5) {
break;
}
}
}

return couponRecipients;
}
// This is the callback function that will be passed to your function
// This function takes in a single user as an argument
// This function will return true only if the user is eligible to receive a coupon
Expand Down
8 changes: 8 additions & 0 deletions callbacks/src/sendCoupons/sendCoupons.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ const updateUserCouponSent = (user) => {
* - update the user in the database by calling the third callback function
* If the user doesn't have a valid phone number, don't do anything for that user
*/
function sendAllCoupons(users, checkPhoneNumber, printMessage, updateUser) {
for (const user of users) {
if (checkPhoneNumber(user)) {
printMessage(user);
updateUser(user);
}
}
}

module.exports = {
canSendCoupon,
Expand Down
9 changes: 4 additions & 5 deletions callbacks/src/userDatabase/userDatabase.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ const UserDatabase = {

// SOLUTION: this keyword is not bound to the UserDatabase since this was an arrow function
// SOLUTION: change the arrow function into a normal function
addUser: (name, id, phone) => {
this.users.push({ name, id , phone, hasCoupon: false, hasUsedCoupon: false});
addUser: function(name, id, phone) {
this.users.push({ name, id, phone, hasCoupon: false, isEnrolledInRewards: false });
},

// what is wrong with this function?
function loadFromFile : () => {
loadFromFile: function() {
const usersFromFile = require("./usersdb.json");
this.users = usersFromFile;
},

},
};

module.exports = UserDatabase;
Expand Down