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
/* | |
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 | |
} |
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={priceInCents: 0}) { | |
let {name, priceInCents=0, availableSizes} = product; | |
return "$" + (priceInCents / 100).toFixed(2); | |
} |
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 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); |
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
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce#grouping_objects_by_a_property |
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 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); | |
} | |
}) |
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
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, | |
}, |
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
* { | |
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; |
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 getParksByState(parks, state) { | |
let parksByState = []; | |
const parksFilter = parks.filter((parks) => { | |
if (parks.location.state === state) { | |
parksByState.push(parks); | |
} | |
}); | |
return parksByState; | |
} |
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 parkByState(parks) { | |
const result = parks.reduce((acc, park) => { | |
let key = park.location.state; | |
if (!acc[key]) { | |
acc[key] = []; | |
} | |
acc[key].push(park) | |
return acc | |
}, {}); |
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
// 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); |