Skip to content

Instantly share code, notes, and snippets.

View stoneboyindc's full-sized avatar

Nick Chang stoneboyindc

View GitHub Profile
function listDestinations(destinations) {
let response = "I can tell you about our current recommended destinations. Which one do you want to hear about? ";
let locations = getLocations(destinations);
response += locations.join("; ") + ". ";
response += "Enter a location for more info."
return response;
}
function getLocations(destinations) {
let locations = [];
function shouldWeOrderThisCandy(inventory, candy){
for (let i=0; i<inventory.length; i++){
if (inventory[i].inStock < inventory[i].weeklyAverage && inventory[i].candy===candy)
return true;
}
}
return false;
}
function userHasVisitedParkOnWishlist(users, user1, user2) {
const vist = users[user1].visited;
const wish = users[user2].wishlist;
return vist.some((park) => wish.includes(park));
}
function getUsersForUserWishlist(users, user1) {
const usernames = Object.keys(users);
return usernames.reduce((acc, username) => {
let visited = userHasVisitedParkOnWishlist(users, username, user1);
function numberOfBorrows(account, books) {
// match account id with books borrows id
acc = 0;
books.forEach(book => {
for (let i = 0; i < book.borrows.length; i++) {
console.log(book.borrows[i].id);
if (book.borrows[i].id === account.id) {
acc += 1;
}
}
const { welcome, goodbye, tell } = require("../utils/fortune-teller");
function getFortune(question) {
tell(question).then(msg => {
console.log(`Your question was: ${question}`);
console.log(`Your fortune is: ${msg}`)})
.catch(err => console.log('There was an error: A question is required...'));
}
function fullSession(question) {
function getFortune(question) {
tell(question).then(msg => {
console.log(`Your question was: ${question}`);
console.log(`Your fortune is: ${msg}`)})
.catch(err => console.log('There was an error: A question is required...'));
}
function secretPasscode(code) {
let errors = [];
if (code.length < 14) errors.push("Code is too short!");
if (code.length > 14) errors.push("Code is too long!");
if (!code.includes("-")) errors.push("Code is missing a '-'.");
if (code !== "jWhyYFh-eTx3qt") errors.push("Code is incorrect.");
if (errors.length > 0) {
throw errors;
}
function getWishlistParksForUser(parks, users, username) {
const wish = users[username].wishlist
return parks.filter((park) => wish.includes(park.id));
}
function allCandyOrders(inventory) {
let result = {};
for (let i=0; i<inventory.length; i++) {
if (inventory[i].inStock < inventory[i].weeklyAverage) {
result[inventory[i].candy]= inventory[i].weeklyAverage * 2;
} else {
result[inventory[i].candy] = 0;
}
}
return result;
@stoneboyindc
stoneboyindc / solution.js
Last active June 9, 2021 01:55
getMostCommonGenres()
function getMostCommonGenres(books) {
let countObj = {};
books.forEach(aBook => {
if (countObj[aBook.genre] != null) {
countObj[aBook.genre]++;
} else {
countObj[aBook.genre] = 1;
}
});
let countArray = [];