This file contains hidden or 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
| import { useState, useEffect } from 'react'; | |
| import { Routes, Route } from 'react-router-dom'; | |
| import CountryDetails from './components/CountryDetails'; | |
| import CountriesList from './components/CountriesList'; | |
| import Navbar from './components/Navbar'; | |
| // import countryListData from './countries.json'; | |
| import axios from 'axios'; | |
| function App() { |
This file contains hidden or 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
| import { useState } from 'react'; | |
| import contactList from './contacts.json'; | |
| function App() { | |
| const [contacts, setContacts] = useState(contactList.slice(0, 5)); | |
| const handleAddRandomContact = () => { | |
| const remainingContacts = contactList.filter((contact) => { | |
| return !contacts.includes(contact); | |
| }); |
This file contains hidden or 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
| class SortedList { | |
| constructor() { | |
| this.items = []; | |
| this.length = 0; | |
| } | |
| add(item) { | |
| this.items.push(item); | |
| this.items.sort((a, b) => a - b); | |
| this.length = this.items.length; |
This file contains hidden or 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
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
| <meta http-equiv="X-UA-Compatible" content="ie=edge" /> | |
| <!-- link the font awesome CDN --> | |
| <link | |
| href="https://use.fontawesome.com/releases/v5.0.1/css/all.css" |
This file contains hidden or 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
| // Iteration #1: Find the maximum | |
| function maxOfTwoNumbers(a, b) { | |
| if (a > b) { | |
| return a; | |
| } else { | |
| return b; | |
| } | |
| // return a > b ? a : b; | |
| // return Math.max(a, b); | |
| } |
This file contains hidden or 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 sum(a, b) { | |
| if (typeof a === 'undefined' && typeof b === 'undefined') { | |
| return 0; | |
| } else if (typeof b === 'undefined') { | |
| return a + 0; | |
| } else { | |
| return a + b; | |
| } | |
| } |
This file contains hidden or 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 ColorSquare = (props) => { | |
| return ( | |
| <div | |
| style={{ | |
| display: 'block', | |
| width: '2em', | |
| height: '2em', | |
| backgroundColor: `rgb(${props.r}, ${props.g}, ${props.b})`, | |
| }} | |
| ></div> |
This file contains hidden or 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
| import { useState, useEffect } from 'react'; | |
| import CountriesList from './components/CountriesList'; | |
| import Navbar from './components/Navbar'; | |
| import { Routes, Route } from 'react-router-dom'; | |
| import CountryDetails from './components/CountryDetails'; | |
| function App() { | |
| const [countries, setCountries] = useState([]); |
This file contains hidden or 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
| import React, { useState } from 'react'; | |
| import foods from './foods.json'; | |
| const MealBox = (props) => { | |
| const [quantity, setQuantity] = useState(1); | |
| const meal = props.meal; | |
| const handleQuantityChange = (event) => { | |
| const { value } = event.target; |
This file contains hidden or 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
| class SortedList { | |
| constructor() { | |
| this.items = []; | |
| this.length = 0; | |
| } | |
| add(item) { | |
| this.items.push(item); | |
| this.items.sort((a, b) => { | |
| if (a > b) { |
NewerOlder