if($(this).children().is(':checked')){ $(this).addClass('active'); } else { $(this).removeClass('active'); }
$(this).addClass('active').siblings().removeClass('active');
const groupQuestions = arr => ({
testId: arr[0].testId,
questions: Object.values(arr.reduce((acc, n) => {
const id = n.questionId;
(acc[id] = acc[id] || {
questionId: id,
questionText: n.questionText,
answers: [],
}).answers.push({
answer: n.answer,
isRight: n.isRight,
});
return acc;
}, {})),
});
const data = [
{
floors: [ 1 ],
limits: [
{ f: 1.26, max: 120 },
{ f: 1.24, max: 140 },
{ f: 1.23, max: 160 },
{ f: 1.22, max: 200 },
{ f: 1.20, max: 260 },
{ f: 1.19, max: 300 },
],
},
{
floors: [ 2, 3 ],
limits: [
{ f: 1.00, max: 100, excludeMax: true },
{ f: 1.30, max: 130 },
{ f: 1.27, max: 160 },
{ f: 1.24, max: 200 },
{ f: 1.22, max: 300 },
],
},
];
const d = data.find(n => n.floors.includes(floors.value));
if (d) {
const v = area.value;
console.log((d.limits.find(n => n.excludeMax ? n.max > v : n.max >= v) || { f: 1 }).f);
}
.todo-list-item.done { text-decoration: line-through; };
this.setState({ done: true });
true
назначать, а переключать текущее значение на противоположное?<span className= {classNames} onClick= {this.onLabelClick} >{ label } <button type="button" onClick= {this.onMarkClick }
class App extends React.Component {
state = {
tasks: [
{
id: 1,
title: 'title',
description: 'description',
},
],
}
createTask = () => {
this.setState(({ tasks }) => ({
tasks: [
...tasks,
{
id: 1 + Math.max(0, ...tasks.map(n => n.id)),
title: 'title',
description: 'description',
},
],
}));
}
render() {
return (
<div>
<button onClick={this.createTask}>Добавить задачу</button>
<ul>
{this.state.tasks.map(({ id, title, description }) => (
<li key={id}>id: {id} | {title} | {description}</li>
))}
</ul>
</div>
);
}
}
arr.filter(n => n % 10 === 4)
// или
arr.filter(n => ''.endsWith.call(n, 4))
// или
arr.filter(n => `${n}`.slice(-1) === '4')
// или
arr.filter(n => /4$/.test(n))
// или
(`${arr}`.match(/\d*4(?=\D|$)/g) || []).map(Number)
.icon {
display: inline-flex;
justify-content: center;
align-items: center;
font-size: 50px;
padding: 0.2em;
width: 1.5em;
height: 1.5em;
border-radius: 100%;
color: #fff;
background: #0f0;
}
.icon::before {
content: attr(data-char);
font-size: 1em;
}
<a class="icon" data-char="¶"></a>
<a class="icon" data-char="X"></a>
<a class="icon" data-char="?"></a>
const Block = ({ items }) => (
<div className="info">
<ul>{items.map(n => <li>{n}</li>)}</ul>
</div>
);
class App extends React.Component {
state = {
items: [
[ 'hello, world!!', '69' ],
[ 'fuck the world', '187' ],
[ 'fuck everythign', '666' ],
],
selected: null,
}
onClick = e => {
this.setState({
selected: +e.currentTarget.dataset.index,
});
}
render() {
const { items, selected } = this.state;
return (
<div>
<div className="wrap">
{items.map((n, i) => (
<div
className={`wrap__el ${i === selected ? 'active' : ''}`}
onClick={this.onClick}
data-index={i}
>
<Block items={n} />
</div>
))}
</div>
<div className="result">
{selected !== null ? <Block items={items[selected]} /> : null}
</div>
</div>
);
}
}
const count1 = [
num => (('' + num).match(/1/g) || []).length,
num => num.toString().replace(/[^1]/g, '').length,
num => `${num}`.split('').filter(d => !~-d).length,
num => [...String(num)].reduce((s, d) => s + (d == 1), 0),
num => ''.split.call(num, 1).length - 1,
];
const numbers = [
23489,
-11,
-93481,
7211231,
0,
123.321,
Infinity,
NaN,
];
count1.map(f => numbers.filter(n => f(n) === 2)).forEach(n => console.log(n));
this
перед preventDefaults
в методе handleDrop
. create: function() {
на create: function(e, ui) {
. document.querySelector('.nav__list').addEventListener('click', function(e) {
const sub = e.target.nextElementSibling;
if (sub && sub.classList.contains('nav__sublist')) {
sub.classList.toggle('nav--show');
}
});
<input type="date" v-model="years.start">
<input type="date" v-model="years.end">
<div v-for="n in months">
<h3>{{ n.year }}, {{ n.name }}</h3>
<div>{{ n.days }}</div>
</div>
data: () => ({
years: {
start: null,
end: null,
},
}),
computed: {
months() {
const start = moment(this.years.start).startOf('month');
const end = moment(this.years.end).endOf('month');
const months = [];
for (; start < end; start.add(1, 'day')) {
const [ year, name, day ] = start.format('YYYY.MMMM.D').split('.');
if (day === '1') {
months.push({
year,
name,
days: [],
});
}
months[months.length - 1].days.push(+day);
}
return months;
},
},