function getCombination(arr, n) {
const sortedArr = JSON.parse(JSON.stringify(arr)).sort();
const results = [];
const part = [];
for(let i = 0; i < sortedArr.length; i++) {
part.push(sortedArr[i]);
const summ = part.reduce((a, b) => a + b);
if (summ === n) {
results.push([...part]);
}
if (summ > n) {
part.pop();
i = sortedArr.indexOf(part[part.length - 1]);
part.pop();
}
}
return results;
}
console.log(getCombination([7, 8, 3, 4, 5, 6, 1, 2], 8));
// [[1, 2, 5], [1, 3, 4], [1, 7], [2, 6], [3, 5], [8]]
const script = document.createElement('script');
script.type = "text/javascript";
script.src="https://code.jquery.com/jquery-3.5.1.min.js";
document.head.appendChild(script);
let time = 0;
const buttons = $("button");
eachButtons();
function eachButtons() {
$.each(buttons , (index, button) => {
const text = $(button).text();
if(text.includes("Кнопка ")) {
clickButton(index, button, time);
time+=1000;
}
});
}
function clickButton(index, button, t) {
setTimeout(function(){
$(button).click();
console.log($(button).text())
if (index === buttons.length - 1) {
time = 1000;
eachButtons();
}
}, t);
}
function validator(value) {
return {
equal(array) {
if(array.toString() === value.toString()) {
return true;
} else {
return false;
}
},
isArray() {
if(Array.isArray(value)) {
return this;
} else {
return false;
}
},
isString() {
if(typeof value === "string") {
return true;
} else {
return false;
}
},
isNumber() {
if(typeof value === "number") {
return true;
} else {
return false;
}
}
}
}
console.log(validator('1').isArray()); // false
console.log(validator([]).isArray().equal([1, 2, 3])); // false
console.log(validator([1, 2, 3]).isArray().equal([1, 2, 3])); // true
console.log(validator('1').isString()); // true
console.log(validator('1').isNumber()); // false
pagenavjs({
pageContainer: '#content',
navContainer: '#pagination'
});
function pagenavjs(params) {
// Что то там ...
params.pageContainer
params.navContainer
}
<div class="block">
<center>lol</center>
<center>kek</center>
azaza
</div>
var block = document.querySelector(".block");
var centerElements = block.querySelectorAll("center");
centerElements.forEach(center => {
center.insertAdjacentHTML('afterend', center.innerHTML);
center.remove()
})