Skip to content

Instantly share code, notes, and snippets.

View josecarneiro's full-sized avatar

José Carneiro josecarneiro

View GitHub Profile
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];
// Iteration 1
function maxOfTwoNumbers(a, b) {
if (a > b) return a;
return b;
}
// Iteration 2
function findLongestWord(arrayOfWords) {
if (arrayOfWords.length === 0) {
// ITERATION 1
// Suspects Collection
const suspectsArray = [];
// Rooms Collection
const roomsArray = [];
// Weapons Collection
const weaponsArray = [];
// 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);
/* 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;
// 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;
// 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');
// 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');
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;
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);