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
import * as yup from 'yup'; | |
import cleanDeep from 'clean-deep'; | |
import { INewDriver, IReplacedCar, ISvZak, ITransport } from 'AppFeatures/ETRN/types/IEtrnContent'; | |
import { isObjectNotEmpty } from 'AppFeatures/ETRN/lib'; | |
yup.setLocale({ | |
mixed: { | |
required: 'Обязательное поле', | |
}, | |
string: { |
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 a Promise which resolves with a value in form of a tuple. | |
* @param promiseFn A Promise to resolve as a tuple. | |
* @returns Promise A Promise which resolves to a tuple of [error, ...results] | |
*/ | |
export function tuple (promise) { | |
return promise | |
.then((...results) => [null, ...results]) | |
.catch(error => [error]) | |
} |
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
export const useToggleBool = (defaultValue = false): [boolean, { open: VoidFunction; close: VoidFunction; toggle: VoidFunction }] => { | |
const [state, setState] = useState<boolean>(() => defaultValue); | |
const open = () => setState(true); | |
const close = () => setState(false); | |
const toggle = () => setState((prevState) => !prevState); | |
const methods = useMemo(() => ({ open, close, toggle }), []); | |
return [state, methods]; | |
}; |
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
export const debounce = (func: AnyFunction, wait: number) => { | |
let timer: number | null = null; | |
return function (this: unknown, ...args: unknown[]) { | |
const onComplete = () => { | |
func.apply(this, args); | |
timer = null; | |
}; | |
if (timer) { |
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
decimalToBinary(3); // 11 | |
decimalToBinary(8); // 1000 | |
decimalToBinary(1000); // 1111101000 | |
function decimalToBinary(digit) { | |
if(digit >= 1) { | |
if (digit % 2) { | |
return decimalToBinary((digit - 1) / 2) + 1; | |
} else { | |
return decimalToBinary(digit / 2) + 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
var string = "Welcome to this Javascript Guide!"; | |
// Output becomes !ediuG tpircsavaJ siht ot emocleW | |
var reverseEntireSentence = reverseBySeparator(string, ""); | |
// Output becomes emocleW ot siht tpircsavaJ !ediuG | |
var reverseEachWord = reverseBySeparator(reverseEntireSentence, " "); | |
function reverseBySeparator(string, separator) { | |
return string.split(separator).reverse().join(separator); |
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
var m = [1, 7, 5, 13, 8], | |
count = m.length - 1, | |
max; | |
for (var i = 0; i < count; i++) { | |
for (var j = 0; j < count - i; j++) { | |
if (m[j] > m[j + 1]) { | |
max = m[j]; | |
m[j] = m[j + 1]; | |
m[j + 1] = max; | |
} |
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
isPalindrome("racecar"); // true | |
isPalindrome("race Car"); // true | |
function isPalindrome(word) { | |
// Уберём все символы, не являющиеся буквами | |
var lettersOnly = word.toLowerCase().replace(/\s/g, ""); | |
// Сравним строку с её перевёрнутой версией | |
return lettersOnly === lettersOnly.split("").reverse().join(""); | |
} |
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
type Color = { r: number, g: number, b: number }; | |
function hexToRgb(hex: string): Color { | |
if (hex.length === 3) { | |
let [hr, hg, hb] = hex.split(''); // ['F', '0', '0'] | |
return hexToRgb(`${hr}${hr}${hg}${hg}${hb}${hb}`); | |
} | |
let [r, g, b] = [0, 2, 4] | |
.map(offset => hex.substring(offset, offset + 2)) // ['FF', '00', '00'] | |
.map(hex => parseInt(hex, 16)); // [255, 0, 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
checkTargetClick( event ) { | |
if ( this.state.mode === 'click' && | |
event.target !== this.tooltip && | |
!this.tooltip.contains( event.target ) ) { | |
this.setState({ show: false }); | |
} | |
} |
NewerOlder