AddProduct={this.props.addProduct}this.props.addProduct(product);
const today = new Date().getDate();
const select = document.querySelector('select');
const toggle = option => option.disabled = option.value < today;select.querySelectorAll('option').forEach(toggle);
// или
Array.prototype.forEach.call(select, toggle);
// или
for (const n of select.options) {
toggle(n);
}
// или
for (let i = 0; i < select.children.length; i++) {
toggle(select.children[i]);
}
// или
(function next(i, n = select.item(i)) {
if (n) {
toggle(n);
next(-~i);
}
})(0);
// или
const next = n => n && (next(n.nextElementSibling), toggle(n));
next(select.firstElementChild);
const duplicateContent = el =>
// можно добавить копии вложенных узлов
el.append(...el.cloneNode(true).childNodes);
// или добавить копию разметки
// el.insertAdjacentHTML('beforeend', el.innerHTML);
// или перезаписать разметку в удвоенном виде
// el.innerHTML += el.innerHTML;
// el.innerHTML = el.innerHTML.repeat(2);
// el.innerHTML = Array(3).join(el.innerHTML);
// el.innerHTML = String.prototype.concat.apply('', Array(2).fill(el.innerHTML));
// el.innerHTML = el.innerHTML.replace(/.+/, '$&$&');
// el.innerHTML = /(.+)/.exec(el.innerHTML).join``;document.querySelectorAll('.btn').forEach(duplicateContent);
// или
for (const n of document.getElementsByClassName('btn')) {
duplicateContent(n);
}
const getDuplicatesIndex = (arr, key = n => n) =>
Object.fromEntries(Object
.entries(arr.reduce((acc, n, i) => ((acc[key(n)] ??= []).push(i), acc), {}))
.filter(n => n[1].length > 1)
);Map:const getDuplicatesIndex = (arr, key = n => n) =>
new Map(Array
.from(arr.reduce((acc, n, i) => {
const k = key(n);
acc.set(k, acc.get(k) ?? []).get(k).push(i);
return acc;
}, new Map))
.filter(n => ~-n[1].length)
);
myMap.enterFullscreen()var myMap = new ymaps.Map('map', {<div ref="map"></div>mounted() {
ymaps.ready(() => {
this.map = new ymaps.Map(this.$refs.map, {
...
const isIterable = x =>
x?.[Symbol.iterator] instanceof Function;isIterable([]) // true
isIterable('') // true
isIterable(document.scripts) // true
isIterable(Array().keys()) // true
isIterable((function*(){})()) // true
isIterable() // false
isIterable(null) // false
isIterable(1) // false
isIterable({}) // false
isIterable(isIterable) // false
когда нажимаю на другой блок, то цвет кнопки не становится прежним
transition: background 9999999s;:active вы, очевидно, не разобрались.:checked.
state = {
value: 0,
options: [ 'Не отмечено', 'Отмечено' ],
}
onChange = ({ target: t }) => {
this.setState(() => ({
value: +t[t.dataset.stateAttr],
}));
}
render() {
const { value, options } = this.state;
return (
<div>
<select
value={value}
onChange={this.onChange}
data-state-attr="value"
>
{options.map((n, i) => <option value={i}>{n}</option>)}
</select>
<br />
<label>
<input
type="checkbox"
checked={value}
onChange={this.onChange}
data-state-attr="checked"
/>
{options[value]}
</label>
</div>
);
}
const longestStr = arr.reduce((max, n) => max.length > n.length ? max : n, '');
// или
const longestStr = arr.sort((a, b) => b.length - a.length)[0];
// или
const longestStr = arr.reduce((acc, n) => (acc[n.length] = n, acc), []).pop();function max(data, key = n => n) {
const getVal = key instanceof Function ? key : n => n[key];
let result = null;
for (const n of data) {
const val = getVal(n);
result = result?.[1] >= val ? result : [ n, val ];
}
return result?.[0];
}
const longestStr = max(arr, 'length');
data: () => ({
status: '',
...computed: {
statuses() {
return [...new Set(this.characters.map(n => n.status))];
},
...<select v-model="status">
<option value="">< ALL ></option>
<option v-for="n in statuses">{{ n }}</option>
</select>computed: {
filteredCharacters() {
const search = this.search.toLowerCase();
const status = this.status;
return this.characters.filter(n => (
(!search || n.name.toLowerCase().includes(search)) &&
(!status || status === n.status)
));
},
...
const getRepetition = (arr, repeated) => Array
.from(arr.reduce((acc, n) => acc.set(n, -~acc.get(n)), new Map))
.reduce((acc, n) => (n[1] === repeated && acc.push(n[0]), acc), []);function getRepetition(arr, repeated) {
const result = [];
const count = {};
for (const n of arr) {
if (!count.hasOwnProperty(n)) {
count[n] = 0;
}
count[n]++;
}
for (const n in count) {
if (count[n] === repeated) {
result.push(+n);
}
}
return result;
}