<span id="total">0</span> <button id="action">+1</button>
const action = document.querySelector('#action');
const total = document.querySelector('#total');
let counter = readCounterFromStorage();
updateStorageAndElement();
action.addEventListener('click', () => {
counter++;
updateStorageAndElement();
})
function readCounterFromStorage() {
return parseInt(localStorage.getItem('counter')) || 0;
}
function updateStorageAndElement() {
total.innerText = counter;
localStorage.setItem('counter', counter);
}
const data = {
"index.js": ["foo.js"],
"foo.js": ["baz.js", "lol.js"],
"baz.js": ["bar.js", "lem.js"],
"bar.js": ["baz.js", "k.js"]
};
function searchCircularDepengency(entry = "index.js", path = []) {
const branch = data[entry];
const newPath = [...path, entry];
console.log("Path", newPath);
// Если есть вложенные элементы,
if (branch) {
// проверить каждый
branch.forEach((nextEntry) => {
// на предмет прохожения ранее,
if (path.includes(nextEntry)) {
console.warn(
"Found Circular Depengency " + nextEntry + " in " + entry,
path
);
// если нет идти глубже
} else {
searchCircularDepengency(nextEntry, newPath);
}
});
} else {
console.log("Branch complite. All OK!");
}
}
console.log(searchCircularDepengency());
$(function() {
const worksSlider = $('[data-slider="slick"]');
/* Filter
=====================*/
let filter = $("[data-filter]");
filter.on("click", function(event) {
event.preventDefault();
changeBlocksVisibility($(this).data('filter'))
});
});
$().ready(() => changeBlocksVisibility("female"));
function changeBlocksVisibility(cat = 'all') {
if(cat == 'all') {
$("[data-cat]").removeClass("hide");
} else {
$("[data-cat]").each(function() {
let workCat = $(this).data('cat');
if(workCat != cat) {
$(this).addClass('hide');
} else {
$(this).removeClass('hide');
}
});
}
}
[
"*".repeat(18),
...textArray
.map(words => words.join(" "))
.map(line => {
const pad = (line.length > 16)?''.padStart:''.padEnd;
const lines = [];
let restLine = line;
while(restLine.length > 16) {
const spaceIndex = restLine.lastIndexOf(" ", 16);
lines.push(pad.call(restLine.slice(0, spaceIndex), 16));
restLine = restLine.slice(spaceIndex + 1);
}
lines.push(pad.call(restLine, 16));
return lines;
})
.flat()
.map(line => "*" + line + "*"),
"*".repeat(18)
]
function formatTextArray(textArray, maxLineLength = 16) {
const formatedTextArray = [];
textArray
.forEach(words => {
const line = words.join(" ");
if(line.length > maxLineLength) {
splitLine(line)
.forEach(item => formatedTextArray.push(align(item, false)) );
} else {
formatedTextArray.push(align(line));
}
}, []);
return addBorders(formatedTextArray);
function align(line = "", isLeft = true) {
let newLine;
if(isLeft) {
newLine = line.padEnd(maxLineLength);
} else {
newLine = line.padStart(maxLineLength);
}
return newLine;
}
function splitLine(line) {
if(line.length > maxLineLength) {
const spaceIndex = line.lastIndexOf(" ", maxLineLength);
const lineStartPart = line.slice(0, spaceIndex);
const restLine = line.slice(spaceIndex + 1);
return ([lineStartPart]).concat(splitLine(restLine));
} else {
return [line]
}
}
function addBorders(formatedTextArray, symbol = "*") {
const borderedTextArray = [
symbol.repeat(maxLineLength),
...formatedTextArray,
symbol.repeat(maxLineLength)
];
return borderedTextArray.map(addHorizontalBorders);
function addHorizontalBorders(line) {
return symbol + line + symbol;
}
}
}
document.getElementById("reset").onclick = function ...
html,
body {
height: 100%;
}
const container = document.querySelector(".container");
container.onclick = function(){
container.classList.toggle("container_color_red");
}
var a = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49];
var n = 4;
var result;
result = Array(Math.ceil(a.length / 4)).fill(0).map( (v, i) => a.slice(i*n, (i+1)*n) );
result = Array(Math.ceil(a.length / 4)).fill(0).map( (v, i, array) => ( l = a.slice(i*n, (i+1)*n) ).concat( Array( Math.max(0, n - l.length) ).fill(0) ) );
var rowCode = "var i = 12; var b = 10; var c = (i + b) * 2;";
var re = new RegExp("(\\-?\\d+)","g"); /* учитывает знак числа (отрицательное или положительное) */
/* var re = new RegExp("(\\d+)","g"); \\ не учитывает знак числа (сумма по абсолютному значению) */
var nums = rowCode.match(re);
var result;
if(nums){
result = nums.reduce(function(sum, num){
return sum += +num;
},0);
console.log("Сумма чисел: " + result);
} else {
console.log("Чисел нет");
}