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
<div class="container"> | |
<div class="inner"> | |
<div class="text"> | |
Lorem ipsum dolor sit amet. | |
</div> | |
</div> | |
</div> |
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
//Добавить событие longtap, которое возникает при длительном (1с) нажатии на элемент | |
//Переопределяется метод addEventListener у прототипа Element, таким образом, что: | |
//Если новый метод вызывается для события touchstart, то callback метода декорируется: | |
//- у элемента проставляется флаг isTouched | |
//- перед вызовом исходного callback запускается timeout, по окончании которого проверится флаг isTouched и вызовется запуск события longtap | |
//Если новый метод вызывается для события touchend, то callback метода декорируется: | |
//- снимается флаг isTouched | |
const longtapEvent = new Event("longtap"); |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="Call any function just once within a period of time"> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<input type="button" value="Call function 3 times" onclick="onClick()"> |
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 ARR_MIN_LENGTH = 5; | |
var ARR_MAX_LENGTH = 10; | |
var arr = getArbitraryArray(); | |
//var arr = [1, 10, 3, 2, 7, 3, 8, 9]; | |
console.log(arr, find(arr, 10)); | |
//arr - массив натуральных чисел. | |
function find(arr, target) { |
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
"use strict"; | |
var m = 3; | |
var n = 4; | |
function next(seq) { | |
//find i, seq[i] < m, seq[i + 1] = seq[n] = m | |
var i = n - 1; | |
console.log(seq); | |
while (i >= 0 && seq[i] == m) { |
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
//Find longest sequence of zeros in binary representation of an integer. | |
function solution(n) { | |
var str = toBinaryString(n).replace(/0+$/, ""); | |
var arr = str.split("1").filter(function(e) { return e.length > 0; }); | |
if (arr.length === 0){ | |
return 0; | |
} | |
arr.sort(function(a, b){ return b.length - a.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
"use strict"; | |
//An equilibrium index of a sequence is an index into the sequence such that the sum of elements at lower indices is equal to the sum of elements at higher indices. | |
//two loops | |
function eq(arr) { | |
if (arr.length === 0) { | |
return -1; | |
} | |
for (var i = 0; i < arr.length; i++) { |
NewerOlder