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
$host = 'localhost'; | |
$db = 'test'; | |
$user = 'root'; | |
$pass = 'root'; | |
$charset = 'utf8mb4'; | |
$dsn = "mysql:host=$host;dbname=$db;charset=$charset"; | |
$opt = [ | |
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, | |
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, |
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
setTimeout(() => { | |
console.log('hello from timeout!') | |
}) | |
let sum = 0 | |
for (let i = 1; i <= 1000000000; i++) { | |
sum++ | |
} | |
console.log(sum) |
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 getArrayFromLinkedList(linkedList) { | |
const arr = [] | |
while (linkedList !== null) { | |
const value = linkedList.value | |
arr.push(value) | |
linkedList = linkedList.next | |
} | |
return 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
/** Slightly changed problem description **/ | |
// Какой вариант лучше и почему? Может оба неудачные? | |
// 1 | |
function DumbConstructorA() { } | |
DumbConstructorA.prototype.dumbMethod = function() { return 123 } | |
// 2 | |
function DumbConstructorB() { | |
this.dumbMethod = function() { return 123 } | |
} |
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
// names может быть как массивом, так и строкой. Как избавиться от любых условий при выводе списка names? | |
function namesFunc(names) { | |
if(names instanceof Array) | |
console.log(names.join(', ')); | |
else | |
console.log(names); | |
} | |
/*** Solution ***/ |
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
// Как избавиться от переменной that в этом примере? То есть не сохранять явно контекст родителя в переменную. | |
function parent() { | |
var that = this; | |
that.multiplier = 3; | |
return [33, 77, 99, 81, 55].map(function(I) { return I * that.multiplier}); | |
} | |
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
/** | |
* Checks if array has all specified keys | |
* | |
* Returns false if some keys are missing and true if all keys are present | |
* | |
* @param $array | |
* @param $keys | |
* @return bool | |
*/ | |
function hasArrayAllSpecifiedKeys($array, $keys) { |
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 delay(ms) { | |
const promise = new Promise((resolve) => { | |
setTimeout(() => resolve(), ms); | |
}); | |
return promise; | |
} | |
delay(1000).then(() => console.log('asdsad')); |
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 getMatchesCountOnStr(str, pattern) { | |
// Find all occurrences, case-insensitive | |
const regexp = new RegExp(pattern, 'ig'); | |
return str.match(regexp)?.length; | |
} |
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
// Matches all HTML elements, even if they have attributes | |
let regexp1 = /<\w+\s?.*?>.*?<\/\w+>/g; | |
let str1 = '<span class="qweqwe"></span> <h1>asd</h1>'; | |
console.log( str1.match(regexp1) ); // (2) ["<span class="qweqwe"></span>", "<h1>asd</h1>"] |
NewerOlder