:class="className". Ну и документацию почитайте.
numbers = [n for n in range(1000, 10000)]numbers = list(range(1000, 10000))
<Range steps={[ 500, 1000, 5000, 10000 ]} />class Range extends React.Component {
state = {
value: this.props.steps[0],
}
onChange = ({ target: { value } }) => {
this.setState({
value: this.props.steps.reduce((closest, n) =>
Math.abs(closest - value) < Math.abs(n - value) ? closest : n
),
});
}
render() {
const { steps } = this.props;
return (
<div>
<input
type="range"
min={steps[0]}
max={steps[steps.length - 1]}
value={this.state.value}
onChange={this.onChange}
/>
<p>{this.state.value}</p>
</div>
);
}
}
const classes = [
{ maxLen: 15, name: 'length-15' },
{ maxLen: 30, name: 'length-30' },
{ maxLen: 45, name: 'length-45' },
];
document.querySelectorAll('.container').forEach(n => {
const len = n.textContent.length;
const cls = classes.find(m => m.maxLen >= len);
if (cls) {
n.classList.add(cls.name);
}
});
echo explode('-', (explode('/', $page)[3]))[2];preg_match('~colors\-is\-(\w+)~', $page, $match);
echo $match[1];
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 = `${containerSelector} .name`;
const text = 'some name 1';for (const n of document.querySelectorAll(textSelector)) {
if (n.innerText === text) {
n.closest(containerSelector).style.visibility = 'hidden';
}
}.hidden {
visibility: hidden;
}document.querySelectorAll(containerSelector).forEach(function(n) {
n.classList.toggle('hidden', this(n.querySelector(textSelector).textContent));
}, RegExp.prototype.test.bind(RegExp(text, 'i')));