forked from theutpal01/HacktoberFest2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilities.js
37 lines (25 loc) · 1000 Bytes
/
utilities.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// This is a collection of some useful functions in JavaScript, which have proved them useful to many of my projects
// Max and Min
export const max = (a, b) => (a > b ? a : b);
export const min = (a, b) => (a < b ? a : b);
// The Sleep function for to delay the execution of a process
export const sleep = (seconds) => {
return new Promise((resolve) => setTimeout(resolve, seconds * 1000));
};
// The function to copy the text to the clipboard
export const copy = (text) => {
navigator.clipboard.writeText(text);
};
// The function to omit a particluar key from an object
export const omit = (key, { [key]: _, ...rest }) => rest;
// The function to produce random numbers between a range
export const random = (min, max) =>
Math.floor(Math.random() * (max - min + 1)) + min;
// The function to remove selected elements from an array
export const remove = (arr, ...args) => {
let _arr = arr.slice();
args.forEach((val) => {
_arr.splice(_arr.indexOf(val), 1);
});
return _arr;
};