text={<a href="https://toster.ru">toster</a>}
arr.sort((a, b) => (a.finishedDate || a.createdDate) - (b.finishedDate || b.createdDate));
Добавляется еще один дополнительный параметр, такой как статус)
status: 'started' или status: 'finished'.
Как можно поставить элемент со статусом started в начало массива?
arr.sort((a, b) => {
const aStatus = a.status !== 'started';
const bStatus = b.status !== 'started';
const aDate = a.finishedDate || a.createdDate;
const bDate = b.finishedDate || b.createdDate;
return (aStatus - bStatus) || (aDate - bDate);
});
Ругается на: aStatus - bStatus
The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
Но если присвоить тип этим переменным эни, то работает супер-пупер
any
, превращайте значения в числа явным образом:const aStatus = +(a.status !== 'started');
const bStatus = +(b.status !== 'started');
Приноровился к angular 2+
:ease="Elastic.easeOut.config(1, 0.75)"
document.querySelector('input').addEventListener('input', e => {
const
val = e.target.value,
reg = RegExp(val, 'gi'),
keys = [ 'firstName', 'lastName' ];
document.querySelector('.autocomplete-suggestions__list').innerHTML = val && people
.map(n => keys.map(k => n[k]).join(' '))
.filter(n => (reg.lastIndex = 0, reg.test(n)))
.map(n => `<div>${n.replace(reg, '<strong>$&</strong>')}</div>`)
.join('');
});
const containerSelector = '.field';
const textSelector = '.name';
const text = 'some name 1';
document.querySelectorAll(`${containerSelector} ${textSelector}`).forEach(n => {
if (n.innerText.indexOf(text) !== -1) {
n.closest(containerSelector).style.visibility = 'hidden';
}
});
.hidden {
visibility: hidden;
}
for (const n of document.querySelectorAll(containerSelector)) {
n.classList.toggle('hidden', n.querySelector(textSelector).textContent.includes(text));
}
.html($(this).find('img'))
.html($(this).find('img').clone())
class App extends React.Component {
state = {
maxCount: 55,
people: [],
url: 'https://swapi.dev/api/people/',
}
fetchPeople() {
fetch(this.state.url).then(r => r.json()).then(r => {
this.setState(({ people, maxCount }) => ({
people: [ ...people, ...r.results ].slice(0, maxCount),
url: r.next,
}));
});
}
updateGenderCount() {
this.setState(({ people }) => ({
genderCount: people.reduce((acc, n) => {
acc[n.gender] = (acc[n.gender] || 0) + 1;
return acc;
}, {}),
}));
}
componentDidMount() {
this.fetchPeople();
}
componentDidUpdate(prevProps, prevState) {
const count = this.state.people.length;
if (count !== prevState.people.length) {
this.updateGenderCount();
if (this.state.url && count < this.state.maxCount) {
this.fetchPeople();
}
}
}
render() {
return (
<div>
<pre>{JSON.stringify(this.state.genderCount, null, 2)}</pre>
</div>
);
}
}
.items-left
, а проверяете количество .items-right
. Думали, что класс сам собой заменится? Нет, так не будет. $('#dateStart').trigger('change');
this.dispatchEvent(new Event('input'));