This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function additionalCapacity (campgrounds) { | |
let totalnum = 0; | |
for (let i=0; i< campgrounds.length; i++) { | |
if(campgrounds[i].isReserved === false) { | |
totalnum += campgrounds[i].partySize; | |
} | |
} | |
return totalnum; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ClickTimes() { | |
function handleClick(e) { | |
e.preventDefault(); | |
console.log('The link was clicked.'); | |
} | |
return ( | |
<button onClick={handleClick}> | |
Click me | |
</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getPriceInDollars(product) { | |
let noValue = '$0.00'; | |
if (product == null) { | |
return noValue; | |
} | |
let {name, priceInCents, availableSizes} = product; | |
if (priceInCents == null) { | |
return noValue; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function calculateTotal(cart) { | |
let result = 0; | |
for (let name in cart) { | |
const item = cart[name]; | |
result += item.quantity * item.priceInCents; | |
} | |
return result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function printCartInventory(cart) { | |
let result = ''; | |
let quantName = ''; | |
for (let name in cart) { | |
const item = cart[name]; | |
const itemQuant = item.quantity; | |
result += `${itemQuant}x${name}\n`; | |
} | |
return result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function joinSizes(productA, productB) { | |
const result = [...productA.availableSizes, ...productB.availableSizes]; | |
return result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// return true if size exists | |
function checkForSizeByName(products, name, size) { | |
if (!products) return false; | |
let item = null; | |
for (let i = 0; i < products.length; i++) { | |
let productInd = products[i] | |
if (productInd.name === name) { | |
item = productInd; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function campgroundCapacity(arr) { | |
let count = 0; | |
for (let i = 0; i < arr.length; i++) { | |
count += arr[i].partySize | |
} return count | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const axios = require("../utils/axios"); | |
const BASE_URL = "http://localhost:5000"; | |
function updateIfExists(id, body) { | |
const url = `${BASE_URL}/constellations/${id}`; | |
return axios | |
.get(url) | |
.then((response) => { | |
if (response==null) { | |
throw 'not found'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function update(constellation) { | |
try { | |
const url = `${BASE_URL}/constellations/${constellation.id}`; | |
return await axios.put(url, constellation); | |
} catch (err) { | |
const id = constellation.id; | |
return Promise.reject(`{ error: 'Updating constellation (id: ${id}) failed.'`); | |
} | |
} |