🔧 Added rust utils, organized js/ts utils
This commit is contained in:
parent
7a55c03644
commit
ca3e7c506d
3 changed files with 5 additions and 0 deletions
22
utils/js_ts/utils.js
Normal file
22
utils/js_ts/utils.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
const factorial = (n) => {
|
||||
if (n < 0) throw new Error("Cannot calculate factorial of negative number");
|
||||
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;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue