const Comments = ({ items }) =>
Array.isArray(items) && items.length
? <React.Fragment>{items.map(n =>
<div className="comment" key={n.id}>
<h3>{n.name}</h3>
<div>{n.body}</div>
<Comments items={n.reply} />
</div>)}
</React.Fragment>
: null;
async function request(data) {
let result = data;
do {
result = await запрос(result);
} while (result не тот, который нужен);
return result;
}function requestRecursive(data) {
return запрос(data).then(result => {
return result тот, который нужен
? result
: requestRecursive(result);
});
}
const values = Object.values(obj);const count = values.flat().length;
// или
const count = [].concat(...values).length;
// или
const count = values.reduce((acc, n) => acc + n.length, 0);
// или
const count = eval(values.map(n => n.length).join('+')) || 0;
a = [ 1, 2, 3 ];
b = [ 4, 5, 6 ];
c = a;
// здесь должен быть какой-то код
console.log(a); // [ 4, 5, 6 ]
console.log(b); // [ 1, 2, 3 ]
console.log(a === c); // trueb.splice(0, b.length, ...a.splice(0, a.length, ...b));
const index = myCollection.indexOf(e.get('target'));
alert(myCoords[index].text);
data: () => ({
image: 0,
images: [ 'раз картинка', 'два картинка', 'три картинка' ],
}),<button v-for="(n, i) in images" @click="image = i">
Показать картинку #{{ i }}
</button>
<transition name="image" mode="out-in">
<img :key="image" :src="images[image]">
</transition>.image-enter-active,
.image-leave-active {
transition: opacity .3s;
}
.image-enter,
.image-leave-to {
opacity: 0;
}
const filteredProducts = [
[ true, n => n.type === 'Bras' ],
[ true, n => n.price <= tempPrice ],
[ color !== 'all', n => n.color === color ],
[ cup, n => n.cup.includes(cup) ],
[ shipping, n => n.freeShipping === true ],
[ search, n => n.title.toLowerCase().startsWith(search.toLowerCase()) ],
].reduce((products, [ active, fn ]) => {
return active
? products.filter(fn)
: products;
}, storeProducts);
this.setState({ filteredProducts });
Вариант добавить в лоб, как я сделал это выше class='test', не сработал.
Этот класс применился к input. А мне нужно применить класс к самому select, который появляется перед закрывающим тегом body.
Array.from(new Set(arr.flat()))
// или, без создания промежуточного массива
[...arr.reduce((acc, n) => (n.forEach(m => acc.add(m)), acc), new Set)]Object.keys([].concat(...arr).reduce((acc, n) => (acc[n] = 1, acc), {}))
// или
Array.prototype.concat.apply([], arr).filter((n, i, a) => i === a.indexOf(n))
// или
`${arr}`.split(',').reduce((acc, n) => (acc.includes(n) || acc.push(n), acc), [])
// или
String(arr).match(/\w/g).sort().filter((n, i, a) => n !== a[i - 1])
// или
arr.toString().match(/(\w)(?!.*\1)/g) || []
function someFunction([ ,,, id,, status ]) {function someFunction({ 3: id, 5: status }) {
this внутри обработчика клика? Не тем, что вам кажется. Замените $(this).attr("href") на $(event.target).attr("href") или стрелочную функцию на обычную.
msg.razd массив значений:const arr = Object.values(msg.razd);.const categories = arr.flatMap(n => n.category);
// или
const categories = [].concat.apply([], arr.map(n => n.category));
// или
const categories = arr.reduce((acc, n) => (acc.push(...n.category), acc), []);const result = categories.filter(n => expect.includes(n._id));
// или
const result = categories.filter(function(n) {
return this.has(n._id);
}, new Set(expect));
// или
const categoriesObj = Object.fromEntries(categories.map(n => [ n._id, n ]));
const result = expect.reduce((acc, n) => ((n = categoriesObj[n]) && acc.push(n), acc), []);
setTimeout((current) => pika[current].classList.toggle('active'), 100, current)