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
Binary search |
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
Stack | |
Queue | |
Singly linked list | |
https://github.com/trekhleb/javascript-algorithms/blob/master/src/data-structures |
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
// from https://blog.logrocket.com/javascript-typeof-2511d53a1a62 | |
function getType(value) { | |
var regex = /^\[object (\S+?)\]$/; | |
var matches = Object.prototype.toString.call(value).match(regex) || []; | |
return (matches[1] || 'undefined').toLowerCase(); | |
} | |
console.log(type('')); // "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
// from https://medium.com/devschacht/javascripts-new-private-class-fields-c60daffe361b | |
// METHOD 1: constructor property | |
// Not reliable | |
function isArray(value) { | |
return typeof value == 'object' && value.constructor === Array; | |
} | |
// METHOD 2: instanceof | |
// Not reliable since an object's prototype can be changed |
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
Module | |
Branching - чтобы не вызывать каждый раз проверки каких-то параметров. | |
Cuггying | |
Memoization | |
Namespace | |
Private - приватные свойства в конструкторе | |
Self-exiting object - Для защиты глобального пространства имён |
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
Object iterate | |
Object clone | |
Is object empty? |
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
bubble | |
cocktail |
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
var el = document.getElementById('el'); | |
document.addEventListener('click', outsideEvtListener); | |
function outsideEvtListener(evt) { | |
if (evt.target === el || el.contains(evt.target)) { | |
return; | |
} | |
// code handling outside click | |
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 declOfNum(number, titles) { | |
cases = [2, 0, 1, 1, 1, 2]; | |
return titles[ (number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5] ]; | |
} | |
use: | |
declOfNum(count, ['найдена', 'найдено', 'найдены']); |