This file contains hidden or 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
| type DebounceFunc = (...args: any[]) => void; | |
| /** | |
| * Creates a debounced function that delays invoking the provided function | |
| * @param {Function} func - The function to debounce wait. | |
| * @param {number} ms - The number of milliseconds to delay. | |
| * @returns {Function} Returns the new debounced function. | |
| */ | |
| function debounce<F extends DebounceFunc>(func: F, ms: number) { | |
| let timeout: ReturnType<typeof setTimeout>; |
This file contains hidden or 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
| function duplicateCount(text) { | |
| return new Set(text.toLowerCase().match(/(.)(?=.*\1)/gi)).size | |
| } | |
| duplicateCount('Indivisibilities') // 2 |
This file contains hidden or 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
| function stringPermutations (str) { | |
| if (str.length <=2) { | |
| return str.length === 2 ? [str, str[1] + str[0]] : [str]; | |
| } | |
| return [...str].reduce((acc, letter, i) => { | |
| const letters = str.slice(0, i) + str.slice(i + 1); | |
| const transformString = stringPermutations(letters).map(item => letter + item); | |
| return [...acc, ...transformString]; | |
| }, []); |
This file contains hidden or 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 UNICODE_SYMBOL = { | |
| dotted: '\u0331', | |
| underline: '\u0332', | |
| through: '\u0336', | |
| } | |
| const format = UNICODE_SYMBOL['through']; | |
| Array.from('Sample Text', (item) => item + format ).join('') // "S̶a̶m̶p̶l̶e̶ ̶T̶e̶x̶t̶" |
This file contains hidden or 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
| function createUUID(){ | |
| var dt = new Date().getTime(); | |
| var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { | |
| var r = (dt + Math.random()*16)%16 | 0; | |
| dt = Math.floor(dt/16); | |
| return (c=='x' ? r :(r&0x3|0x8)).toString(16); | |
| }); | |
| return uuid; | |
| } |
This file contains hidden or 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
| $aroundXYList: top, left, bottom, right; | |
| $sizeList: ( | |
| 0: 0, | |
| 2: 0.2rem, | |
| 4: 0.4rem, | |
| 6: 0.6rem, | |
| 8: 0.8rem, | |
| 10: 1rem, | |
| 12: 1.2rem, |
This file contains hidden or 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
| function formatCurrencyToString(number) { | |
| if (!number) return ''; | |
| return String(number).replace(/(\d+)(\d{1})\d{2}/g, (value, group1, group2) => { | |
| return `${(group2 > 0) ? `${group1}.${group2}` : `${group1}`}k`; | |
| }); | |
| } | |
| formatCurrencyToString(452230) // '452.2k' | |
This file contains hidden or 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
| function App() { | |
| const [value, setValue] = React.useState(""); | |
| const [data, setData] = React.useState([]); | |
| const handlerChange = ({ target: { value } }) => { | |
| setValue(value); | |
| }; | |
| const handlerKeyPress = event => { | |
| if (event.key === "Enter") { |
This file contains hidden or 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
| let cardInput = myform.cardcode; | |
| cardInput.addEventListener('input', formatCardCode, false); | |
| function formatCardCode() { | |
| let cardCode = this.value.replace(/[\D]/g, '').substring(0,16); | |
| cardCode = cardCode != '' ? cardCode.match(/.{1,4}/g).join(' ') : ''; | |
| this.value = cardCode; | |
| } |
This file contains hidden or 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
| npm i natives |