Skip to content

Instantly share code, notes, and snippets.

View stoneboyindc's full-sized avatar

Nick Chang stoneboyindc

View GitHub Profile
/*
The following functions have various syntax errors in them. Fix the bugs to get the tests to pass!
When any of the following function's parameters reference `products`, they are referencing an array full of objects with the following shape:
{
name: "Slip Dress",
priceInCents: 8800,
availableSizes: [ 0, 2, 4, 6, 10, 12, 16 ],
quantity: 0
}
function getPriceInDollars(product={priceInCents: 0}) {
let {name, priceInCents=0, availableSizes} = product;
return "$" + (priceInCents / 100).toFixed(2);
}
@stoneboyindc
stoneboyindc / s.js
Last active December 2, 2022 20:09
It should return an array of all the transactions from the book's `borrows` key. However, each transaction should include the related account information and the `returned` key.
function getBorrowersForBook(book, accounts) {
let result = [];
let borrowArray = book.borrows;
borrowArray.forEach(borrow=>{
let account = accounts.find(acc => acc.id === borrow.id);
let obj = account;
obj['returned'] = borrow.returned;
result.push(obj);
})
console.log(result);
@stoneboyindc
stoneboyindc / reduce()
Created March 1, 2021 23:07
how to use reduce() to group object by a property
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce#grouping_objects_by_a_property
@stoneboyindc
stoneboyindc / solution.js
Last active August 6, 2021 15:32
getBooksPossessedByAccount()
function getBooksPossessedByAccount(account, books, authors) {
//Initialze a return array
let booksPossessed=[];
//check for the account id in the borrows arrays
books.forEach(book => {
let borrowArray = book.borrows;
if (borrowArray.find(borrow => borrow.id === account.id && borrow.returned === false)) {
booksPossessed.push(book);
}
})
@stoneboyindc
stoneboyindc / sortByPrice()
Last active March 1, 2021 16:27
A Webpage preview
window.books = [
{
title: "PROLOG Programming for Artificial Intelligence",
authors: ["Ivan Bratko"],
description:
"Prolog has its roots in logic; however the main aim of this book is to teach Prolog as a practical programming tool.",
price: 89.29,
rating: 4.5,
quantity: 1,
},
* {
font-family: Helvetica;
font-size: 1.4em;
color: rgb(58, 51, 51);
text-align: center;
color: white;
}
.container div:nth-child(1), div:nth-child(6) {
background-color: #B8336A;
function getParksByState(parks, state) {
let parksByState = [];
const parksFilter = parks.filter((parks) => {
if (parks.location.state === state) {
parksByState.push(parks);
}
});
return parksByState;
}
@stoneboyindc
stoneboyindc / parkByState()
Last active February 25, 2021 22:38
solution.js
function parkByState(parks) {
const result = parks.reduce((acc, park) => {
let key = park.location.state;
if (!acc[key]) {
acc[key] = [];
}
acc[key].push(park)
return acc
}, {});
@stoneboyindc
stoneboyindc / solution.js
Last active April 12, 2021 14:32
SetFontSize button
// App
import React, { useState } from "react";
import Content from "./Content";
import Header from "./Header";
function App () {
const [loggedIn, setLoggedIn] = useState(false);
const toggleLoggedIn = () => setLoggedIn(!loggedIn);
const [fontSize, setFontSize] = useState(12);
const increaseSize = () => setFontSize(fontSize+2);