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
//проверка на присутствие числа в аргументе | |
//если хоть один аргумент в массиве совпадает с числом, возвращает true | |
Number.prototype.trueOf = function(...props) { | |
return props.includes(this) | |
} |
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 delAtIdx= (s,i) => s.slice(0,i)+s.slice(i+1) | |
//версия прототипа | |
String.prototype.delAtIdx = function (from, to) { | |
if (!to) to = from | |
to = Math.max(from,to) | |
from = Math.min(from,to) | |
return this.slice(0,from)+this.slice(to+1) | |
} |
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 wheelListener (elem, func) { | |
if (elem.addEventListener) { | |
if ('onwheel' in document) { | |
// IE9+, FF17+ | |
elem.addEventListener("wheel", func); | |
} else if ('onmousewheel' in document) { | |
// устаревший вариант события | |
elem.addEventListener("mousewheel", func); | |
} else { |
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 randMinMax = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min |
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 errorParser = errorStringArray => { | |
// c сервера приходят ошибки в таком формате | |
// errorStringArray = [ | |
// "The AboutMe field is required. (AboutMe)", | |
// "Invalid url format (Contacts->Twitter)", | |
// "Invalid url format (Contacts->Youtube)", | |
// "Invalid url format (Contacts->Vk)" | |
// ] | |
//убираем первую заглавную букву из названий будущих полей переменных |
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
// возвращает массив из необходимого числа элементов needArraySize | |
// рандомных /НЕ ОДИНАКОВЫХ/ целых чисел (from 0 to realArraySize) | |
// к которому можно потом "замапится" для перемешивания значений искомого массива, например: | |
// randomDifferentIntegersArrayCreator(array.length)(from 1 to array.length).map(el=>array[el]) | |
const randomDifferentIntegersArrayCreator = (realArraySize = 1) => | |
(needArraySize = realArraySize) => { | |
const justArray = (a, b = []) => { while (a--) b[a] = a; return b } | |
let arrayOfNumbers = justArray(realArraySize), |
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 query = Object.fromEntries( Object | |
.entries( { | |
page: 77, //этот удалится при значении page: 1 | |
term: '', | |
friend: null, | |
extra: 'Этот ключ не удалится', | |
} ) | |
// чистим дефолтные значения | |
.filter( n => n[1] !== null ) |
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 FIBONACCI(number) | |
Summ = Summ Mod 9 | |
If Summ = 0 Then | |
FIBONACCI = 9 | |
Else | |
FIBONACCI = Summ | |
End If | |
End Function |
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 Foo = Promise<{a: number}> | |
type ExtractPromiseArg<X> = X extends Promise<infer T> ? T : never | |
type FooArg = ExtractPromiseArg<Foo> |
OlderNewer