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
const calculateAverage = array => array.reduce((sum, value) => sum + value, 0) / array.length; | |
const calculateStandardDeviation = values => { | |
const average = calculateAverage(values); | |
const squareDiffs = values.map(value => (value - average) ** 2); | |
return Math.sqrt(calculateAverage(squareDiffs)); | |
} | |
const testShuffler = shuffler => { | |
const array = [1, 2, 3]; |
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
// Iteration 1 | |
function maxOfTwoNumbers(a, b) { | |
if (a > b) return a; | |
return b; | |
} | |
// Iteration 2 | |
function findLongestWord(arrayOfWords) { | |
if (arrayOfWords.length === 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
// ITERATION 1 | |
// Suspects Collection | |
const suspectsArray = []; | |
// Rooms Collection | |
const roomsArray = []; | |
// Weapons Collection | |
const weaponsArray = []; |
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
// ITERATION 2 | |
function selectRandom(array) { | |
const randomIndex = Math.floor(Math.random() * array.length); | |
return array[randomIndex]; | |
} | |
function pickMystery() { | |
const suspect = selectRandom(suspectsArray); | |
const weapon = selectRandom(weaponsArray); |
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
/* eslint no-restricted-globals: 'off' */ | |
// Iteration 1: All rates average - Get the average of all rates with 2 decimals | |
function calculateAverageMovieRate(movies) { | |
if (!movies.length) { | |
return 0; | |
} | |
const arrayOfRates = movies.map(value => { | |
return value.rate; |
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
// ITERATION 1 | |
function updateSubtotal($product) { | |
// Get DOM elements that hold price and quantity | |
const $price = $product.querySelector('.price span'); | |
const $quantity = $product.querySelector('.quantity input'); | |
// Extract values from DOM elements | |
const priceValue = parseFloat($price.innerText); | |
const quantityValue = $quantity.valueAsNumber; |
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
// main.js | |
const chronometer = new Chronometer(); | |
const btnLeft = document.getElementById('btn-left'); | |
const btnRight = document.getElementById('btn-right'); | |
const minDec = document.getElementById('min-dec'); | |
const minUni = document.getElementById('min-uni'); | |
const secDec = document.getElementById('sec-dec'); |
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
// main.js | |
const chronometer = new Chronometer(); | |
const btnLeft = document.getElementById('btn-left'); | |
const btnRight = document.getElementById('btn-right'); | |
const minDec = document.getElementById('min-dec'); | |
const minUni = document.getElementById('min-uni'); | |
const secDec = document.getElementById('sec-dec'); |
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
class SortedList { | |
constructor() { | |
this.items = []; | |
this.length = this.items.length; | |
} | |
add(item) { | |
this.items.push(item); | |
this.items.sort((a, b) => a - b); | |
this.length = this.items.length; |
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
const http = require('http'); | |
const Pokedex = require('pokedex'); | |
const pokedex = new Pokedex(); | |
const server = http.createServer((request, response) => { | |
const endpoint = request.url; | |
const pokemonName = endpoint.substring(1); | |
try { | |
const pokemon = pokedex.pokemon(pokemonName); | |
// console.log(pokemon); |
OlderNewer