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
<html> | |
<head> | |
<style> | |
ul { | |
list-style: none; | |
margin:0; | |
padding: 0; | |
} | |
img { |
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 mongoose = require('mongoose'); | |
const DB_PORT = 27017; | |
const DB_NAME = 'playground'; | |
mongoose.connect(`mongodb://localhost:${DB_PORT}/${DB_NAME}`) | |
.then(() => console.log('Connected to Mongo...')) | |
.catch(err => console.error('Could not connect...', err)) | |
const courseSchema = new mongoose.Schema({ | |
name: String, | |
author: String, |
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 transactions = [ | |
{ id: 1, amount: 100 }, | |
{ id: 2, amount: 200 }, | |
{ id: 3, amount: 300 }, | |
{ id: 4, amount: 450 } | |
] | |
const useReduce = transactions.reduce((acc, curr) => { | |
return acc + curr.amount; | |
},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
let space = [2,3,1,5,3,9]; | |
let x = 2; | |
let results = []; | |
function calculateMaxDisk(seg, arr) | |
{ | |
//calculate amount of modules | |
let module = ((arr.length) - seg) + 1; | |
console.log('this function will create ' + module + " iterations!"); | |
//main loop, creates 'x' amount of iterations | |
for( let i=1 ; i <= module ; i++ ) |
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
//this is an example integer | |
const myInt = 52132; | |
function descendingOrder(n) { | |
if (n > -1) { | |
let toArr = Array.from(String(n), Number); | |
let sorted = toArr.sort((a, b) => a - b).reverse(); | |
let joined = sorted.join(""); | |
return parseInt(joined); | |
} |
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
//this is a mock API I made for the occasion | |
const submitUrl = 'https://retoolapi.dev/QqocMc/data'; | |
//this selects the unordered list with the id 'list' on the html template | |
//you should have that set up beforehand | |
const htmlListNode = document.getElementById('list'); | |
//Use the fetch method and pass it the url of the API | |
fetch(submitUrl) | |
.then(res => res.json()) //parse the response and then... | |
.then(data => { | |
let length = data.length; //save the length of the array to use it as a reference in the loop |
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
//API url | |
const quotesUrl = 'https://quote-garden.herokuapp.com/api/v3/quotes' | |
//my function | |
function myRequest() { | |
//initialize an instance of the XMLHttpRequest object | |
const req = new XMLHttpRequest(); | |
//set the parameters to be used in the get request | |
req.open("GET", quotesUrl, true); | |
//send the get request |
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
//For this gist, I'm using a free, public API that shows information about a user's location based on their IP address | |
//here's where I store the API key I was provided with | |
const myKey = 'c00508dc4104c70518fcf49e17216676'; | |
//here's a random IP from the internet | |
const myIp = '191.101.63.2'; | |
//here's the base url | |
const myUrl = 'http://api.ipstack.com/'; | |
function myRequest() { |
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
//For this gist, I'm using a free, public API that shows information about a user's location based on their IP address | |
//here's where I store the API key I was provided with | |
const myKey = 'c00508dc4104c70518fcf49e17216676'; | |
//here's a random IP from the internet | |
const myIp = '191.101.63.2'; | |
function myRequest(){ | |
//initialize the XMLHttpRequest object | |
const request = new XMLHttpRequest(); |
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 findMultiples() { | |
let baseNumer = 0; | |
for(let i = 0; i<100 ; i++) { | |
baseNumer ++; | |
console.log(baseNumer); | |
if(baseNumer % 3 == 0) { | |
console.log('multiple of 3 found'); | |
} else { | |
if (baseNumer % 5 == 0) { | |
console.log('multiple of 5 found'); |