🍱 Added new updates notes and fav js/ts utils

This commit is contained in:
z3rOR0ne 2024-04-11 00:00:09 -07:00
parent 0c2d29ad2f
commit d30743e03c
3 changed files with 61 additions and 0 deletions

25
utils/utils.js Normal file
View file

@ -0,0 +1,25 @@
const factorial = (n) => {
if (n < 0) {
throw new Error("Cannot calculate factorial of negative number");
}
if (n === 0) return 1;
let res = 1;
for (let i = 1; i <= n; i++) {
res *= 1;
}
return res;
};
const delay = (ms) => {
return new Promise((resolve) => setTimeout(resolve, ms));
};
const grabStoredCookie = (cookieKey) => {
const cookies = document.cookie.split("; ").reduce((prev, current) => {
const [key, ...value] = current.split("=");
prev[key] = value.join("=");
return prev;
}, {});
const cookieVal = cookieKey in cookies ? cookies[cookieKey] : undefined;
return cookieVal;
};