const baseArr = [
[2, 2, 3, 9, 7],
[6, 2, 4, 5, 8],
];
const multDoubles = (arr) => {
const counted = arr.reduce((acc, num, i) => {
if(acc.has(num)) {
acc.get(num).push(i);
return acc;
}
acc.set(num, [i]);
return acc;
}, new Map);
const multedArr = [...arr];
counted.forEach((indexes, num) => {
if(indexes.length > 1) {
const newNum = num * indexes.length;
indexes.forEach((i) => {
multedArr[i] = newNum;
})
}
});
return multedArr;
};
const result = baseArr.map((arr) => multDoubles(arr));
state[0] = state[index] // запись нового выбора на первое место state.splice(index, 1) // удаление нового выбора с предыдущей позиции в массиве
for (let i = 1; i < state.length; i++) { // сортировка от меньшего к большему по первому числу для возврата предыдущего выбора на правильную позицию if (state[i].split(' ')[0] > beforeSelected.split(' ')[0]) { state.splice(i, 0, beforeSelected) // запись предыдущего выбора на правильную позицию break } else if (state[i].split(' ')[0] === beforeSelected.split(' ')[0]) { // если первые числа равны проверка по второму числу if (state[i].split(' ')[2] >= beforeSelected.split(' ')[2]) { state.splice(i, 0, beforeSelected) // запись предыдущего выбора на правильную позицию break } } if (i === state.length - 1) { // если предыдущий выбор оказалася наибольшим state.push(beforeSelected) break } }
const resize = ({ param }) => { // изменение select ... }
const resize = (obj) => { // изменение select
const param = obj.param;
...
}
onClick={() => {
handleClick(item);
handleClick(item);
handleClick(item);
handleClick(item);
}}
let select = document.querySelector(".select-css"); let vval = document.querySelector(".forfor"); let pagiArea = document.querySelector('.pagination');
function getSelectInfo(){ let sql = ''; if (select.value == "dateNew") { sql = 'SELECT * FROM "modScheme"."mod" ORDER BY "date_time" DESC'; } if (select.value == "dateOld") { sql = 'SELECT * FROM "modScheme"."mod" ORDER BY "date_time"'; } if (select.value == "size") { sql = 'SELECT * FROM "modScheme"."mod" ORDER BY "modSize" DESC'; } return sql; }
pagi = pagi + '<a class="firstPagiHref"...'
Кодfunction showPagination(pages, currentPage) { let pagi = '<a href="javascript://" onclick="duol(1)" class="firstPagiHref"><div id="pagiFirst">1</div></a><a class="firstPagiHref2"><div id="pagiTypical">..</div></a>'; if (Number(currentPage) == 1) { pagi = pagi + '<a class="firstPagiHref" href="javascript://" onclick="duol(1)"><div id="pagiTypical" class="currentPagiPage">1</div></a>'; if (pages >= Number(currentPage) + 1) { pagi = pagi + '<a class="firstPagiHref" href="javascript://" onclick="duol(2)"><div id="pagiTypical">2</div></a>'; } if (pages >= Number(currentPage) + 2) { alert(pages); alert(Number(currentPage) + 2); pagi = pagi + '<a class="firstPagiHref" href="javascript://" onclick="duol(3)"><div id="pagiTypical">3</div></a>'; } if (pages >= Number(currentPage) + 3) { pagi = pagi + '<a class="firstPagiHref" hhref="javascript://" onclick="duol(4)"><div id="pagiTypical">4</div></a>'; } if (pages >= Number(currentPage) + 4) { pagi = pagi + '<a class="firstPagiHref" href="javascript://" onclick="duol(5)"><div id="pagiTypical">5</div></a>'; } } else if (Number(currentPage) == 2) { pagi = pagi + '<a class="firstPagiHref" href="javascript://" onclick="duol('+(Number(currentPage) - 1)+')"><div id="pagiTypical">' + (Number(currentPage) - 1) + '</div></a>'; pagi = pagi + '<a class="firstPagiHref" href="javascript://" onclick="duol('+Number(currentPage)+')"><div id="pagiTypical" class="currentPagiPage">'+Number(currentPage)+'</div></a>'; if (pages >= Number(currentPage) + 1) { pagi = pagi + '<a class="firstPagiHref" href="javascript://" onclick="duol('+(Number(currentPage) + 1)+')"><div id="pagiTypical">'+(Number(currentPage) + 1)+'</div></a>'; } if (pages >= Number(currentPage) + 2) { pagi = pagi + '<a class="firstPagiHref" href="javascript://" onclick="duol('+(Number(currentPage) + 2)+')"><div id="pagiTypical">'+(Number(currentPage) + 2)+'</div></a>'; } if (pages >= Number(currentPage) + 3) { pagi = pagi + '<a class="firstPagiHref" href="javascript://" onclick="duol('+(Number(currentPage) + 3)+')"><div id="pagiTypical">'+(Number(currentPage) + 3)+'</div></a>'; } } else { if (pages >= Number(currentPage) -2) pagi = pagi + '<a class="firstPagiHref" href="javascript://" onclick="duol('+(Number(currentPage) - 2)+')"><div id="pagiTypical">'+(Number(currentPage) - 2)+'</div></a>'; if (pages >= Number(currentPage) -1) { pagi = pagi + '<a class="firstPagiHref" href="javascript://" onclick="duol('+(Number(currentPage) - 1)+')"><div id="pagiTypical">'+(Number(currentPage) - 1)+'</div></a>'; } pagi = pagi + '<a class="firstPagiHref" href="javascript://" onclick="duol('+Number(currentPage)+')"><div id="pagiTypical" class="currentPagiPage">'+Number(currentPage)+'</div></a>'; if (pages >= Number(currentPage) + 1) { pagi = pagi + '<a class="firstPagiHref"href="javascript://" onclick="duol('+(Number(currentPage) + 2)+')"><div id="pagiTypical" >'+(Number(currentPage) + 2)+'</div></a>'; } if (pages >= Number(currentPage) + 2) { pagi = pagi + '<a class="firstPagiHref" href="javascript://" onclick="duol('+(Number(currentPage) + 3)+')"><div id="pagiTypical" >'+(Number(currentPage) + 3)+'</div></a>'; } } pagi = pagi + '<a class="firstPagiHref2"><div id="pagiTypical">..</div></a>'+'<a href="javascript://" onclick="duol('+pages+')" class="firstPagiHref"><div id="pagiEnd">'+pages+'</div></a>'; pagiArea.innerHTML = pagi; return (currentPage * 7) - 7; document.querySelector('#ya1').scrollIntoView({ behavior: 'smooth', block: 'start' }) }
function getPagiInfo() { return new Promise(function (resolve, reject) { var request = new XMLHttpRequest(); // Настройка запроса request.open('GET','/pagi/',true); request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); //Подписка на событие onreadystatechange и обработка его с помощью анонимной функции request.addEventListener('readystatechange', function() { // если состояния запроса 4 и статус запроса 200 (OK) if ((request.readyState==4) && (request.status==200)) { let objects = request.responseText; objects = Math.ceil(objects); let currentPage = document.querySelector('.currentPagiPage').innerHTML; let result = showPagination(objects, currentPage); resolve(result); } }); // Отправка запроса на сервер request.send(); }); }
function show(obj) { // расшифровываем json vval.innerHTML = ""; let obj1 = JSON.parse(obj); for (let i=0; i<obj1.length; i++) { vval.innerHTML= vval.innerHTML + '<a href="#" class="hrefCar">'+'<div class="blockTypicalCar">'+'<div class="blockTitle">МОД '+obj1[i]['title']+' ДЛЯ BEAMNG.DRIVE</div>'+'<img src="/asset/other/images/beam.jpg" id="imageCarTipical">'+'<div class="otherContentCar">'+'<div class="someText">'+obj1[i]['textAbout']+'</div>'+'<hr>'+'<div class="infoIcons">'+'<div class="viewsCar"><img src="/asset/other/images/svg/preview.svg"> '+obj1[i]['watches']+'</div>'+'<div class="commentsCar"><img src="/asset/other/images/svg/comment.svg"> '+obj1[i]['comments']+'</div>'+'<div class="downloadsCar"><img src="/asset/other/images/svg/download.svg"> '+obj1[i]['downloads']+'</div>'+'</div>'+'<hr>'+'<a href="#" id="downloadHref" download><div class="donateHeaderButt secondButt"><button>Скачать</button></div></a>'+'</div>'+'</div>'+'</a>'; } }
select.onchange = function () { let sql = getSelectInfo(); let a = getPagiInfo(); let promiseResult = a.then(result => {b = result}).then(() => getObjects(sql, 7, b)); }
function duol(aaa) { let sql = getSelectInfo(); if (aaa != 1) { aaa = (aaa * 7) - 7; } else { aaa = 0; } getObjects(sql, 7, aaa); if (aaa == 0) { aaa = 1; } else { aaa = (aaa / 7) + 1; }
aaa = (aaa + 1) % 7;
const sumFactorials = (maxN) => {
let factorial = 1;
const getNextFactorial = (n) => {
factorial *= n;
return factorial;
}
const adder = (sum, n) =>
n < maxN ?
1 / getNextFactorial(n) + adder(sum, n + 1) :
sum + 1 / getNextFactorial(n);
return adder(0, 1);
}
return sumFactorials(3);
const sumG = (n, g) => {
let sum = 0;
let lastNum = 1;
let str = '';
for (let i = 0; i < n; i++) {
sum += lastNum;
str += `${lastNum} `;
lastNum *= g;
}
str = str.slice(0, -1);
console.log(str);
return sum;
};
console.log(sumG(5,2));
If(b1 > 1) {
let sumG = SumG(5,2)
let sum = "";
let sumG = function (n,g) {
const obj = { a: 1 };
const expectedObj = { a: 2 };
someFunction(obj);
expect(obj).toEqual(expectedObj);
someFunction(JSON.parse(JSON.stringify(obj)))
for (let el = 0; el < moscowCity.length; el++) {
if (secondCity === moscowCity[el].city) {
secondMoscowOrNot = "moscow-city"
} else if (secondCity != moscowCity[el].city) {
secondMoscowOrNot = "not-moscow-city"
}
}
for (let le = 0; le < moscowCity.length; le++) {
if (firstCity === moscowCity[le].city) {
firstMoscowOrNot = "moscow-city"
} else if (firstCity != moscowCity[le].city) {
firstMoscowOrNot = "not-moscow-city"
}
}
const isFirstMoscowCity = moscowCity.some((c) => firstCity === c.city);
const isSecondMoscowCity = moscowCity.some((c) => secondCity === c.city);
const arr = [1, 2, 23, 23, 23, 0, 4, 2, 11, 4, 3, 3, 3, 3, 23, 23]
while(i < arrSort.length-1)
let arrSort = arr.sort((a,b)=> a < b ? -1 : 1)
arr.sort((a, b) => a - b)
let numberNext = 1; let i = 0;
while(i < arrSort.length)
;
let numberNext = 0;
let number = arr[0];
for(let i = 1; i < arr.length; i++) {
if(arr[i] === arr[numberNext]) {
number = arr[numberNext];
continue;
}
numberNext++;
}
numberNext+=1 i++
;
?) (() => {
const fields = [
{
name: 'Car',
options: {
min: 'Audi',
max: 'Big Toyota',
}
},
{
name: 'name',
options: {
min: 'Иван',
max: 'Алексей Иванович',
}
}
];
const origStr = 'Привет, меня зовут {{name}}! У меня есть машина {{car}}';
const replaceKeysToText = (str, optionsKey) =>
str.replace(/\{\{\s*(\w+)\s*\}\}/g, (fullMatch, key) => {
const field = fields.find((f) => f.name.toLowerCase() === key);
if(!field) {
return fullMatch;
}
return field.options[optionsKey];
});
const short = replaceKeysToText(origStr, 'min');
const long = replaceKeysToText(origStr, 'max');
return [short, long];
})()