Skip to content

Instantly share code, notes, and snippets.

View stoneboyindc's full-sized avatar

Nick Chang stoneboyindc

View GitHub Profile
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;
}
function ClickTimes() {
function handleClick(e) {
e.preventDefault();
console.log('The link was clicked.');
}
return (
<button onClick={handleClick}>
Click me
</button>
function getPriceInDollars(product) {
let noValue = '$0.00';
if (product == null) {
return noValue;
}
let {name, priceInCents, availableSizes} = product;
if (priceInCents == null) {
return noValue;
}
@stoneboyindc
stoneboyindc / calculateTotal()
Last active February 24, 2021 01:32
solution.js
function calculateTotal(cart) {
let result = 0;
for (let name in cart) {
const item = cart[name];
result += item.quantity * item.priceInCents;
}
return result;
}
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;
}
function joinSizes(productA, productB) {
const result = [...productA.availableSizes, ...productB.availableSizes];
return result;
}
// 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;
}
}
function campgroundCapacity(arr) {
let count = 0;
for (let i = 0; i < arr.length; i++) {
count += arr[i].partySize
} return count
}
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';
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.'`);
}
}