Skip to content

Instantly share code, notes, and snippets.

View roniceyemeli's full-sized avatar
🏁

Ronice Yemeli roniceyemeli

🏁
View GitHub Profile
@roniceyemeli
roniceyemeli / useFetchData.js
Created June 12, 2023 08:34
useFetchData Hook to improve code reusability and loose component
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);
@roniceyemeli
roniceyemeli / hashtagGenerator.js
Last active October 5, 2022 18:44
hashtag Generator
function generateHashtag (str) {
if (str.trim() === ''){
return false;
}
let newStr = str.split(" ");
let arr = [];
let result = "";
newStr.forEach(el=>{
@roniceyemeli
roniceyemeli / dateReference.js
Created October 4, 2022 16:27
generate a simple Date id (year+month+day)
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;
}
@roniceyemeli
roniceyemeli / checkCashRegister.js
Last active September 29, 2022 13:18
Cash Register freecodecamp
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) {
@roniceyemeli
roniceyemeli / telephoneCheck.js
Last active September 29, 2022 13:07
Telephone Number Validator
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
@roniceyemeli
roniceyemeli / caesarsCipher.js
Last active September 29, 2022 11:29
Caesars Cipher encryption
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 = [];
@roniceyemeli
roniceyemeli / convertToRoman.js
Created September 24, 2022 14:45
Roman Numeral Converter
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];
}
}
@roniceyemeli
roniceyemeli / palindromeChecker.js
Last active September 24, 2022 13:42
Palindrome Checker
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;
@roniceyemeli
roniceyemeli / mapDebris.js
Created September 23, 2022 14:43
Map the Debris , Kepler third law
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)})
}
@roniceyemeli
roniceyemeli / makePerson.js
Created September 23, 2022 00:30
Make a Person algorithm
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() {