Skip to content

Instantly share code, notes, and snippets.

View stoneboyindc's full-sized avatar

Nick Chang stoneboyindc

View GitHub Profile
@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 = [];
@stoneboyindc
stoneboyindc / gist:8e65b3acc19800de83d846b3cb082b65
Created December 18, 2019 15:38
Keep gh pages in sync with master
// Reference: http://lea.verou.me/2011/10/easily-keep-gh-pages-in-sync-with-master/
$ git add .
$ git status // to see what changes are going to be commited
$ git commit -m 'Some descriptive commit message'
$ git push origin master
$ git checkout gh-pages // go to the gh-pages branch
$ git rebase master // bring gh-pages up to date with master
$ git push origin gh-pages // commit the changes
const printNames = names=> {
names.forEach((names)=>
console.log(names));
}
const logTreeType=trees=>{
trees.forEach((tree)=>
console.log(tree.type));
}
/*
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
}
const findStudentScoreByName = require("../src/solution");
const expect = require("chai").expect;
describe("Checking equality", () => {
it("should return a student score if the name matches", () => {
const students = [
{ name: "Leo Yeon-Joo", score: 8.9 },
{ name: "Morgan Sutton", score: 7.4 },
@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);
function listAllItems(products) {
if(products.length === 0){
return `There are no items for sale.`;
}
if(products.length === 1){
return `There is 1 item for sale: ${products[0].name}.`;
}
if(products.length === 2){
return `There are ${products.length} items for sale: ${products[0].name} and ${products[1].name}.`;
// should return all of the books taken out by an account with the author embedded
function getBooksPossessedByAccount(account, books, authors) {
let books_taken = [];
books.forEach(book=>{
if (book.borrows.find(item=>item.id === account.id && !item.returned)) {
books_taken.push(book);
}
})
console.log(books_taken);
books_taken.forEach(book=>{
function addProductToCart({ name, priceInCents }, cart = {}) {
const selected = cart[name];
if (selected) {
selected.quantity++;
} else {
cart[name] = { priceInCents, quantity: 1 };
}
return cart;
}
function printNames (names) {
names.forEach(name => console.log(name));
}
function logTreeType (trees) {
trees.forEach(type => console.log(type.type));
}
function totalPoints(points) {
// your solution here