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
// for big array it is more performant | |
const removeDuplicates = (array) => { | |
const uniqueValues = []; | |
const seenMap = {}; | |
for (const item of array) { | |
if (seenMap[item]) continue; | |
seenMap[item] = true; | |
uniqueValues.push(item); | |
} |
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
/** | |
* Returns the provided URLs search parameters | |
* as a set of key-value pairs. | |
*/ | |
const getURLParameters = (url) => { | |
const { searchParams } = new URL(url); | |
return Object.fromEntries(searchParams); | |
}; |
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
// The below source code performs 20 times faster than the one line version | |
const isObjectEmpty = (object) => { | |
if (object.constructor !== Object) return false; | |
// Iterates over the keys of an object, if | |
// any exist, return false. | |
for (_ in object) return false; | |
return true; | |
}; | |
// one line version |
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
// for lightweight strings this is well-enough | |
const reverse = str => str.split('').reverse().join(''); | |
// more performant way for not lightweight strings :) | |
const reverseString = (string) => { | |
let reversedString = ""; | |
for (let i = string.length - 1; i >= 0; i--) | |
reversedString += string[i]; |
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 getRandomHexColor = () => { | |
const randomValue = Math.floor(Math.random() * 0xffffff); | |
const hexValue = randomValue.toString(16); | |
return hexValue.padStart(6, "0"); | |
}; |
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 elementIsInFocus = (el) => (el === document.activeElement); | |
// Returns true if the element is in focus, otherwise returns false | |
elementIsInFocus(anyElement) |
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 isTabActive = () => !document.hidden;isTabActive() | |
// true|false |
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 judgeDeviceType = | |
() => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|OperaMini/i.test(navigator.userAgent) ? 'Mobile' : 'PC'; | |
judgeDeviceType() | |
// PC | Mobile |
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 copyText = async (text) => await navigator.clipboard.writeText(text) | |
copyText('One Line of Code Front End World') |
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 getSelectedText = () => window.getSelection().toString(); | |
getSelectedText(); //Return selected content |
OlderNewer