const interval = useRef(null);
// ...
interval.current = setInterval(//...
function* counter() {
let i = 0;
while (true) {
yield i++;
}
}
function* map(innerIterator, f) {
for (const value of innerIterator) {
yield f(value);
}
}
function* filter(innerIterator, f) {
for (const value of innerIterator) {
if (f(value)) {
yield value;
}
}
}
function* take(innerIterator, count) {
let i = 0;
for (const value of innerIterator) {
yield value;
if (++i === count) { return }
}
}
function* inspect(innerIterator) {
for (const value of innerIterator) {
console.log(value);
yield value;
}
}
console.log('Создаем итератор');
const iter = inspect(
take(
map(
filter(
counter(),
v => v % 2 === 0
),
v => v * 2
),
30
)
);
console.log('Итератор есть, но он еще ничего не считает: ', iter);
console.log('Вычисления будут по требованию:');
console.log([...iter]);
// хелперы
const makeCustomTextFieldWithState = (): [string, ReactElement] => {
const [value, setValue] = useState<string>('');
const onChange = (event: React.ChangeEvent<HTMLInputElement>) =>
setValue(event.target.value);
return [value, <CustomTextField onChange={onChange} />];
};
const makeManyCustomTextFieldWithState = (count: number): [string[], ReactElement[]] =>
Array(count).fill(0).reduce(([values, elements]) => {
const [value, element] = makeCustomTextFieldWithState();
return [
[...values, value],
[...elements, element],
];
}, [[], []]);
// в компоненте
const [[dept, login, firstName, lastName], elements] = makeManyCustomTextFieldWithState(4);
<>{elements}</>
const sortedMap = new Map([...map.entries()].sort(([, a], [, b]) => b - a));
console.log(sortedMap);
const sorted = [...map.entries()].sort(([, a], [, b]) => b - a);
map.clear();
sorted.forEach(([k, v]) => map.set(k, v));
console.log(map);
const mediaQuery = window.matchMedia('(max-width: 992px)');
const handler = () =>
$(document.body).toggleClass('lock', mediaQuery.matches);
mediaQuery.addListener(handler);
handler();
@media (max-width: 992px) {
body {
/* тут то что у Вас в .lock было */
}
}
const re = /(.+)\[(.+)\]\[(.+)\]/;
const formData = new FormData(drawingForm);
const result = {};
for (const [key, value] of Object.entries(formData)) {
const matches = key.match(re);
if (!matches) { continue }
const [, k1, k2, k3] = matches;
((result[k1] ??= {})[k2] ??= {})[k3] = value;
}
console.log(result); // тут валидация
if (popup1() === random)
соответственно здесь строго сравнивается undefined с числом, что всегда даст false.if (agreement === true)
зачем === true в условии, если agreement всегда типа boolean?