const chunk = (a, n) => a.length > 1 ? [...Array(Math.ceil(a.length / n))].map((_, i) => a.slice(n * i, n + n * i)) : a;
console.log(chunk([0], 2));
let id = 1, name = 'test name', price = 100
const oldArr = [
{ id, name, price},
{ id, name, price},
{ id, name, price}
]
const newArr = oldArr.map(item => ({
code: item.id,
orderName: item.name,
orderPrice: item.price
}))
console.log(newArr)
class Scrolling {
offset = null;
scrolls() {
const isOffset = pageYOffset > 100 ? "offsetOne" : "offsetSecond";
if (this.offset != isOffset) {
this[isOffset]({
registion: document.querySelector("#registion"),
vhod: document.querySelector("#vhod"),
});
this.offset = isOffset;
}
}
offsetOne({ registion, vhod }) {
registion.style.display = "none";
vhod.style.cssText = "background:none;width:30px";
vhod.innerHTML = "<img style='width: 20px; height: 20px;' src='SiteImage/logo_vhod.svg'>";
PanelMenuLinks.style.cssText = "background:none;z-index:-1;margin-top:-45px;font-size:13px;color:#fff;border-top:0;";
block_panel_menu_children.style.top = "10px";
//block_panel_menu - заменить на класс.
document.querySelectorAll("#block_panel_menu").forEach((item) => (item.style.height = "49px"));
document.querySelector("#logotip").style.cssText = "opacity: 0;margin-top:-20px;";
document.querySelector("header").style.height = "50px";
}
offsetSecond({ registion, vhod }) {
registion.style.display = "block";
vhod.style.cssText = "background:#626262;width:100px";
vhod.innerHTML = "Регистрация";
PanelMenuLinks.style.cssText = "background:#E7E7E7;margin-top:0px;font-size:18px;color:#000;border-top:10px solid #fff;";
block_panel_menu_children.style.top = "20px";
//block_panel_menu - заменить на класс.
document.querySelectorAll("#block_panel_menu").forEach((item) => (item.style.height = "70px"));
document.querySelector("#logotip").style.cssText = "opacity:1;margin-top:0px;";
document.querySelector("header").style.height = "70px";
}
}
const scroll = new Scrolling();
window.addEventListener("scroll", scroll.scrolls.bind(scroll), false);
class MyClass {
method() {
console.clear();
console.log(Reflect.has(this, 'secondMethod')) // true
console.log(this.hasOwnProperty('secondMethod')); // false
console.log('secondMethod' in this) // true
console.log(this.secondMethod !== undefined) // true
}
secondMethod() {
}
}
let myClass = new MyClass();
myClass.method();
function compare(one = '', second = '') {
let oneArray = one.match(/([a-zA-Z]+)|(\d+)/g);
let secondArray = second.match(/([a-zA-Z]+)|(\d+)/g);
if (oneArray && oneArray[0] > 10) return false;
if (!oneArray || !secondArray) return false;
if (oneArray[0] != secondArray[0]) return false;
if (parseInt(oneArray[1]) < parseInt(secondArray[1])) {
return true;
}
return false;
}
console.log(compare('ty12', 'ty33')); // true
console.log(compare('ty121', 'ty33')); // false
console.log(compare('ty121', 'tyt33')); // false
const chunk = (a, n) => [...Array(Math.ceil(a.length / n))].map((_, i) => a.slice(n * i, n + n * i));
console.log(chunk([0,1,2,3,4,5,6,7,8,9,10,11,12], 6));
//0: [0, 1, 2, 3, 4, 5]
//1: [6, 7, 8, 9, 10, 11]
//2: [12]
document.getElementById("button540").onclick = myFunction540;
function myFunction540() {
const phone = document.getElementById("phone540").value;
if (!phone) {
alert("заполните phone");
return false;
}
_rc("send", "order", {
orderMethod: "one-click",
name: document.getElementById("name540").value,
phone
});
}
let data = new FormData();
data.append('file', input.files[0]);
const options = {
method: 'POST',
body: data
}
const response = await fetch('url', options);
const res = await response.json();
console.log(res);
const json = `[{"id":124124,"firstname":"Районный","lastname":"Прокурор","warns":0,"role":11,"flip":0,"rank":"Участник","ban":false,"isBanned":"Нет","tempban":0,"mute":0,"mutesleft":0,"violations":0,"botmute":0,"nick":"хай"},{"id":123123,"firstname":"Кто","lastname":"Никто","warns":0,"role":11,"flip":0,"rank":"Участник","ban":false,"isBanned":"Нет","tempban":0,"mute":0,"mutesleft":0,"violations":0,"botmute":0,"nick":"пока"},{"id":125125,"firstname":"Крутой","lastname":"Поц","warns":0,"role":1,"flip":0,"rank":"Участник","ban":false,"isBanned":"Нет","tempban":0,"mute":0,"mutesleft":0,"violations":0,"nick":"привет"}]`;
const data = JSON.parse(json);
function findNick(arr, nick) {
const res = arr.find(i => i.nick == nick);
if (res) return;
return arr;
}
console.log(findNick(data, 'хай'));
<script>
function changeIMG(){
var pattern=/id=(.+)/g;
var ans=pattern.exec(location.href);
if (ans[1]=='lyubov')
document.getElementById('img2change').src = 'картинка1';
if (ans[1]=='morkov')
document.getElementById('img2change').src = 'картинка2';
}
document.addEventListener("DOMContentLoaded", changeIMG)
</script>