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
// ============================================== | |
//Add timeout to any function | |
const timeout = (ms, cb) => { | |
let timer = setTimeout(() => { | |
if (timer) console.log('was expired') | |
timer = null | |
}, ms) | |
return (...args) => { | |
if (timer) { | |
cb(...args) |
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 cutStrByWord(string, number = 15, endChar = '') { //принимает строку, сколько слов оставить, что добавить в конце строки | |
if (typeof string !== 'string') { | |
console.warn('Function minStrByWord (TypeError: string (first arg) : Передайте строку)') | |
return false | |
} | |
if (typeof number !== 'number') { | |
console.warn('Function minStrByWord (TypeError number (second arg): Передайте число)') | |
return false | |
} | |
let strCopy = string; |
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 user = { | |
'userName': 'r2d2', | |
[Symbol('password')]: 'c3po' | |
}; | |
console.log(Object.keys(user)); | |
console.log(Object.getOwnPropertyNames(user)); | |
console.log(Object.getOwnPropertySymbols(user)); | |
Reflect.ownKeys(user); |
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 getRandomInt(min, max) { | |
return 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
/* | |
Фуекциональное программирование (Декларативность - т.е описывается, что представляет собой проблема и ОЖИДАЕМЫЙ РЕЗУЛЬТАТ от функции.) (абстрагируемся от принципа кода функции, важен результат) | |
Императивность - т.е забота сводится КАК достичь результата (сам принцип достижения). | |
Концепции | |
1) Неизменяемость (Задача №2, Задача №3) - т.е исходные данные не "мутируем" | |
2) Чистые функции (Задача №2, Задача №3) - т.е ничего глобально не изменяют | |
2.1 Функция должна получать как минимум один аргумент | |
2.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 sumRange(first, last) { | |
let mid, res, count, mainmid, secondmid; | |
if (last % 2 == 0) { | |
mid = last / 2; | |
res = (first + last) * mid; | |
count = 3; | |
} else { | |
mainmid = Math.floor(last / 2); | |
secondmid = Math.ceil(last / 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
let arr = [ | |
[1, 2, 3, 4], | |
[5, 6, 7, 8], | |
[9, 10, 11, 12], | |
[13, 14, 15, 16] | |
]; | |
console.log(arr); | |
console.log(getColumns(arr)); | |
console.log(getDiagonalLeftRight(arr)); |
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
HTML | |
<div class="calendar"> | |
<div class="info"></div> | |
<!-- /.info --> | |
<table> | |
<thead> | |
<tr> | |
<td>пн</td> |
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 arr = [3, 1, 4, 2]; | |
console.log(selectionSort(arr)); | |
function selectionSort(arr) { | |
let result = []; | |
let length = arr.length; | |
for (let i = 0; i < length; i++) { | |
let min = findSmallest(arr); |
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 arrRange = createArrRange(1, 10); | |
//Принимает массив с диапазоном чисел, второй параметр искомое число, Возвращает индекс элемента + сколько операций выполнил | |
console.log(binarySearch(arrRange, 5)); | |
function binarySearch(arrRange, userNum) { | |
let first = 0; |
NewerOlder