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
import {useState, useEffect} from 'react' | |
const useFetchData = (url:string)=> { | |
const [data, setData] = useState(null); | |
const [loading, setLoading] = useState(true); | |
useEffect(() => { | |
setLoading(true); | |
fecth(url) | |
.then((res) => response.json()) | |
.then((data) => { | |
setData(data); |
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 generateHashtag (str) { | |
if (str.trim() === ''){ | |
return false; | |
} | |
let newStr = str.split(" "); | |
let arr = []; | |
let result = ""; | |
newStr.forEach(el=>{ |
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 dateRef = () => { | |
let now = new Date(); | |
timestamp = now.getFullYear().toString(); // 2011 | |
timestamp += (now.getMonth < 9 ? '0' : '0') + now.getMonth().toString(); | |
timestamp += ((now.getDate < 10) ? '0' : '0') + now.getDate().toString(); | |
return timestamp; | |
} |
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 lookup = { "ONE HUNDRED": 10000, "TWENTY": 2000, "TEN": 1000, "FIVE": 500, "ONE": 100, "QUARTER": 25, "DIME": 10, "NICKEL": 5, "PENNY": 1 } | |
function checkCashRegister(price, cash, cid) { | |
let change = (cash - price) * 100; | |
let cidTotal = 0; | |
let state = []; | |
cid.forEach(el => { | |
cidTotal += el[1] * 100 | |
}); | |
if (change === cidTotal) { |
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 telephoneCheck(str) { | |
let patterns = [ | |
/^(1\s?)?\d{3}([-\s]?)\d{3}([-\s]?)\d{4}$/, /^(1\s?)?\(\d{3}\)\s?\d{3}[-\s]?\d{4}$/ | |
] | |
return patterns.some( rgx => rgx.test(str)) | |
} | |
// telephoneCheck("555-555-5555"); will return true |
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 rot13(str) { | |
let key = 13; | |
let lowerAlphabet = 'abcdefghijklmnopqrstuvwxyz' | |
let upperAlphabet = 'abcdefghijklmnopqrstuvwxyz'.toUpperCase(); | |
let lowerAlphabetArr = lowerAlphabet.split(''); | |
lowerAlphabetArr.push(...lowerAlphabetArr.splice(0,key)) | |
let alphabetPushed = lowerAlphabetArr.join('') | |
let alphabetPushedUp = alphabetPushed.toUpperCase(); | |
let strEncoded = []; | |
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 convertToRoman(num) { | |
let numObject = { M: 1000, CM: 900, D: 500, CD: 400, C: 100, XC: 90, L: 50, XL: 40, X: 10, IX: 9, V: 5, IV: 4, I: 1 } | |
let romanNumber= []; | |
for (let value in numObject) { | |
while (num >= numObject[value]) { | |
romanNumber += value; | |
num -= numObject[value]; | |
} | |
} |
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 palindrome(str) { | |
str = str.toLowerCase(); | |
let spaceRgx = /\s+|\W+|_/g; | |
str = str.replace(spaceRgx, ""); | |
str = str.split(''); | |
let arrayReversed = str.slice().reverse(); | |
if (arrayReversed.join('') !== str.join('')) { | |
return false; | |
} | |
return true; |
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 orbitalPeriod(arr) { | |
const GM = 398600.4418; | |
const earthRadius = 6367.4447; | |
const orbitalPeriod = (x) => { | |
return Math.round(2*Math.PI*Math.sqrt((Math.pow(earthRadius + x,3))/(GM))) | |
} | |
let newArr = []; | |
arr.forEach(el =>{ | |
newArr.push({name:el.name, orbitalPeriod: orbitalPeriod(el.avgAlt)}) | |
} |
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 Person = function (firstAndLast) { | |
// Only change code below this line | |
// Complete the method below and implement the others similarly | |
let fullName = firstAndLast; | |
this.getFirstName = function() { | |
return fullName.split(" ")[0]; | |
}; | |
this.getLastName = function() { |
NewerOlder