const getMostCommonSymbol = (str) => {
const sortedSymbols = str.split('').sort().join('');
const countedSymbols = [...sortedSymbols.matchAll(/(.)\1*/g)];
return countedSymbols.reduce(
(acc, [row, symbol]) =>
acc.count < row.length ? { symbol, count: row.length } : acc,
{ symbol: null, count: 0 }
);
}
getMostCommonSymbol('asdasda')
const arr = Array.from(
new Set(Array.from(document.querySelectorAll('.shop_name'), n => n.innerText)),
n => ({ name: n })
);
const arr = Object.values(Array.prototype.reduce.call(
document.getElementsByClassName('shop_name'),
(acc, { textContent: name }) => (acc[name] ??= { name }, acc),
{}
));
document.querySelector('.case-print')
function waitForElementAndClick(selectors, checkInterval = 100) {
return new Promise((resolve) => {
let intervalId = setInterval(() => {
if (document.querySelector(selectors) != null) {
document.querySelector(selectors).click()
clearInterval(intervalId)
resolve()
}
}, checkInterval)
});
}
import vk_api
token = ""
id_group = айди_группы
vk = vk_api.VkApi(token=token)
longpoll = VkBotLongPoll(vk, id_group)
getting_api = vk.get_api()
def otpravitel(id, message):
vk.method("messages.send", {"user_id": id, "message": text, 'random_id': 0})
while True:
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
if event.from_user:
id = event.object.message['from_id']
mes = event.object.message['text']
if mes == 'Привет, как дела?'
otpravitel(id, 'Привет, отлично, у тебя?')
else:
otpravitel(id, 'Я не понял вас')
continue
wrapper.innerHTML = Array
.from(word.value, n => obj[n] ? `<img src="${obj[n]}">` : '')
.join('');
for (let n = null; n = wrapper.lastChild; n.remove()) ;
for (const n of word.value) {
if (obj.hasOwnProperty(n)) {
const img = new Image;
img.src = obj[n];
wrapper.append(img);
}
}
// или
wrapper.replaceChildren(...Array.prototype.reduce.call(
word.value,
(acc, n) => (
obj[n] && ((acc[acc.length] = new Image).src = obj[n]),
acc
),
[]
));
while (word.value.length < wrapper.children.length) {
wrapper.removeChild(wrapper.lastElementChild);
}
while (word.value.length > wrapper.children.length) {
wrapper.appendChild(document.createElement('img'));
}
Array.prototype.forEach.call(wrapper.children, (n, i) => {
const src = obj[word.value[i]];
if (!(n.hidden = !src)) {
n.src = src;
}
});
let obj = { 'а': 'https://github.com/itsFide/converter/blob/master/img/а.png?raw=true', 'А': 'https://github.com/itsFide/converter/blob/master/img/а.png?raw=true', 'б':'https://github.com/itsFide/converter/blob/master/img/б.png?raw=true', ...
const obj = Object.fromEntries(Array.prototype.flatMap.call(
'абвгдеёжзийклмнопрстуфхцчшщъыьэюя', n => {
const url = `https://github.com/itsFide/converter/blob/master/img/${n}.png?raw=true`;
return [
[ n, url ],
[ n.toUpperCase(), url ],
];
}
));
interface SomeType {}
class SomeClass {
static getSymbols(): SomeType;
static getSymbols(getSymbolsOnly: true): string[];
static getSymbols(getSymbolsOnly: false): SomeType;
static getSymbols(getSymbolsOnly: boolean = false): string[] | SomeType {
if(getSymbolsOnly) {
return [];
}
return {};
}
}
const t1 = SomeClass.getSymbols(); // SomeType
const t2 = SomeClass.getSymbols(true); // string[]
const t3 = SomeClass.getSymbols(false); // SomeType
const button = document.querySelector('.test')
const updateProp = () => {
const confirmResult = confirm(
'Вы действительно хотите изменить значение ключа у объекта или получить данный объект в консоль?'
);
if (!confirmResult) {
console.log('Вы отменили данное действие');
return;
}
const promptResult1 = prompt('Введите желаемый ключ');
if (!promptResult1.includes('_')) {
const promptResult2 = prompt('Введите желаемое значение');
proxy[promptResult1] = promptResult2
}
console.log(proxy[promptResult1])
}
button.addEventListener('click', updateProp)
const person = {
name: 'Maxim',
job: 'Junior Fronted-Developer',
age: 15
}
const handler = {
get(target, props) {
let arr = props.split('_').map((el) => (`${el}: ${target[el] ?? 'Такого ключа не существует'}`));
return arr.join(', ');
},
set(target, key, prop) {
if (!target[key]) {
console.log('Не верная запись');
return;
}
if (prop === null) {
console.log('Значение не указано');
return;
}
const confirmResult = confirm(
`Подтвердить изменение данного ключа (${key}) на значение ${prop}?`
)
if (!confirmResult) {
console.log('Действие отменено');
return;
}
switch (key) {
case 'age':
if (prop <= 0 || prop > 100) {
console.log(`Слишком ${prop > 100 ? 'высокий' : 'маленький'} возраст`);
return;
}
target[key] = prop;
return;
default:
target[key] = prop;
}
}
}
const proxy = new Proxy(person, handler);
const SECTIONS = [
'top',
'bottom',
'head',
'shoes',
'bag',
'accs',
];
const prepareShareItems = () => {
const { person, items } = store.getState().globals;
const result = SECTIONS.reduce((acc, section) => {
const personSection = person[section];
const { slide } = personSection;
const itemId = personSection.list[slide];
const item = items.find((item) => item.id === itemId);
acc[section] = item?.image;
return acc;
}, {});
return result;
}
{
const max1 = 9;
const max2 = 30; // max of two nums
let cur = max2 / max1;
const inc = cur;
const len = 3;
const log = (a, b) => {
console.log(b > -Infinity ? `a: ${` ${a}`.slice(-len)} | b: ${` ${b}`.slice(-len)}` : `a: ${` ${a}`.slice(-len)} |`)
}
log(0, 0);
for(let i = 1, j = 1; i < max2; i++) {
const nums = [i];
if(i >= cur) {
nums.push(j);
j++;
cur += inc;
}
log(...nums);
}
log(max2, max1);
}