nums1 = nums1.slice(0, m).concat(nums2).sort((a, b) => a - b);
nums1.splice(0, nums1.length, ...[ ...nums1.slice(0, m), ...nums2 ].sort((a, b) => a - b));
// или
nums1.slice(0, m).concat(nums2).sort((a, b) => a - b).forEach((n, i) => nums1[i] = n);
<a :href="category.link">
router-link
, или уберите ссылки.v-if
) содержимое этого объекта.props: [ 'start', 'end', 'title', 'delay' ],
data: () => ({
val: null,
}),
created() {
this.val = this.start;
const interval = setInterval(() => {
if (++this.val >= this.end) {
clearInterval(interval);
}
}, this.delay);
},
<div>
<h3>{{ title }}</h3>
<div>{{ val }}</div>
</div>
data: () => ({
counters: [
{ start: -20, end: 69, title: 'hello, world!!', delay: 40 },
{ start: 0, end: 187, title: 'fuck the world', delay: 45 },
{ start: 400, end: 666, title: 'fuck everything', delay: 20 },
],
}),
<v-counter
v-for="n in counters"
v-bind="n"
/>
data: () => ({
width: 0,
}),
computed: {
itemSize() {
return this.width > 700 ? 46 : 56;
},
},
methods: {
onResize() {
this.width = window.innerWidth;
},
},
created() {
this.onResize();
window.addEventListener('resize', this.onResize);
},
beforeDestroy() {
window.removeEventListener('resize', this.onResize);
},
// или
data: () => ({
itemSize: null,
}),
created() {
const mql = window.matchMedia('(max-width: 700px)');
const onChange = () => this.itemSize = mql.matches ? 56 : 46;
onChange();
mql.addEventListener('change', onChange);
this.$on('hook:beforeDestroy', () => mql.removeEventListener('change', onChange));
},
:item-size="itemSize"
const ceil = (value, precision) => Math.ceil(value / precision) * precision;
const values = [ 1, 2, 3, 163, 200.001, 99.999 ];
values.map(n => ceil(n, 1)); // [ 1, 2, 3, 163, 201, 100 ]
values.map(n => ceil(n, 10)); // [ 10, 10, 10, 170, 210, 100 ]
values.map(n => ceil(n, 5)); // [ 5, 5, 5, 165, 205, 100 ]
class App extends React.Component {
state = {
items: [
{ id: 69, text: 'hello, world!!' },
{ id: 187, text: 'fuck the world' },
{ id: 666, text: 'fuck everything' },
],
active: null,
}
onClick = e => {
this.setState({
active: +e.target.dataset.index,
});
}
render() {
const { items, active } = this.state;
return (
<div>
{items.map((n, i) => (
<div
key={n.id}
data-index={i}
className={i === active ? 'active' : ''}
onClick={this.onClick}
>{n.text}</div>
))}
</div>
);
}
}
function findN([...arr]) {
const index = arr.sort((a, b) => a - b).findIndex((n, i) => i !== ~-n);
return -~index || -~arr.length;
}
Желательно, чтобы вычислительная сложность была O(n)
const findN = arr => -~arr
.reduce((acc, n) => (acc[~-n] = !1, acc), Array(-~arr.length).fill(!0))
.findIndex(Boolean);
const findN = arr =>
arr.reduce((acc, n) => acc - n, (arr.length + 2) * (arr.length + 1) / 2);
const findN = arr =>
arr.reduce((acc, n, i) => acc ^ n ^ -~i, -~arr.length);
const Header = ({ Top }) => (
<div className="navHeader">
<Top />
</div>
);
...
<Header Top={Top} />
class TabContent extends React.Component {
render() {
const { title, content } = this.props;
return (
<div className="tabcontent">
<h3>{title}</h3>
<p>{content}</p>
</div>
);
}
}
class Tabs extends React.Component {
state = {
active: null,
}
openTab = e => this.setState({
active: +e.target.dataset.index,
});
render() {
const { items } = this.props;
const { active } = this.state;
return (
<div>
<div className="tab">
{items.map((n, i) => (
<button
className={`tablinks ${i === active ? 'active' : ''}`}
onClick={this.openTab}
data-index={i}
>{n.title}</button>
))}
</div>
{items[active] && <TabContent {...items[active]} />}
</div>
);
}
}