new Date(str.split(' ', 1)[0].split('.').reverse().join('-')).toLocaleString('ru-RU', {
month: 'long',
day: 'numeric',
})
const $checkbox = $('.form__chekbox');
const $cbAll = $checkbox.filter('.form__chekbox_all');
const $cb = $checkbox.not($cbAll);
$cbAll.change(e => $cb.prop('checked', false));
$cb.change(() => {
const $checked = $cb.filter(':checked');
const allChecked = $checked.length === $cb.length;
$cbAll.prop('checked', !$checked.length || allChecked);
$cb.prop('checked', (i, val) => allChecked ? false : val);
});
function App(props) {
const [ items, setItems ] = React.useState([...props.items]);
const [ name, setName ] = React.useState('');
const add = () => setItems([
...items,
{
id: 1 + Math.max(0, ...items.map(n => n.id)),
name,
},
]);
return (
<div>
<div>
<input onChange={e => setName(e.target.value)} />
<button onClick={add}>add</button>
</div>
{items.map(n => (
<div key={n.id}>
{Object.entries(n).map(([ k, v ]) => <div>{k}: {v}</div>)}
</div>
))}
</div>
);
}
mounted() {
const observer = new IntersectionObserver(entries => {
if (entries[0].isIntersecting) {
stopObservation();
// здесь запрашивайте свои данные
}
}, {
threshold: 1,
});
observer.observe(this.$el);
const stopObservation = () => observer.disconnect();
this.$on('hook:beforeDestroy', stopObservation);
},
new Date instanceof Object // true
/(?=.*1)(?=.*2)(?=.*3)/.test(str)
[ 1, 2, 3 ].every(n => str.includes(n))
new Set(str.match(/[123]/g)).size === 3
props: [ 'value', 'placeholder' ],
<div>
<input
:class="value ? 'input_filled' : ''"
:value="value"
@input="$emit('input', $event.target.value)"
>
<span>{{ placeholder }}</span>
</div>
Как можно дополнить мой код, чтобы он проверял то, что требуется?
И можно как-нибудь без объявления переменной n внутри функции?
const getMaxDepth = arr =>
Array.isArray(arr)
? 1 + Math.max(0, ...arr.map(getMaxDepth))
: 0;
console.log(getMaxDepth([ 1, [ 2 ], [ [ 3 ] ], [ [ [ 4 ] ] ] ])); // 4
console.log(getMaxDepth([])); // 1
console.log(getMaxDepth(666)); // 0
const createArr = (source, maxLength) =>
[...Array(1 + Math.random() * maxLength | 0)].map(() => source[Math.random() * source.length | 0]);
const [ arr1, arr2, arr3 ] = [...Array(3)].map(() => createArr(arr, 5));
const createArr = ([...source], maxLength) => Array.from(
{ length: Math.min(source.length, 1 + Math.random() * maxLength | 0) },
() => source.splice(Math.random() * source.length | 0, 1)[0]
);
function createArr(source, maxLength) {
const arr = source.slice();
for (let i = arr.length; --i > 0;) {
const j = Math.random() * (i + 1) | 0;
[ arr[j], arr[i] ] = [ arr[i], arr[j] ];
}
return arr.slice(0, 1 + Math.random() * maxLength | 0);
}
function createTable(rows, cols) {
const maxLen = `${rows * cols}`.length;
return [...Array(rows)]
.map((n, i) => [...Array(cols)]
.map((m, j) => `${cols * i + j + 1}`.padStart(maxLen, 0))
.join(' '))
.join('\n');
}
function createTable(rows, cols) {
const zeroStr = Array(1 + Math.ceil(Math.log10(rows * cols + 1))).join(0);
let result = '';
for (let i = 0; i < rows; i++) {
result += i ? '\n' : '';
for (let j = 0; j < cols; j++) {
result += (j ? ' ' : '') + (zeroStr + (cols * i + j + 1)).slice(-zeroStr.length);
}
}
return result;
}
const SHOW_INITIAL = 3;
const SHOW_MORE = 5;
const listSelector = '.myList';
const itemSelector = 'li';
const showSelector = '.loadMore';
const hideSelector = '.showLess';
$(listSelector)
.on('click', showSelector, function({ delegateTarget: t }) {
$(`${itemSelector}:hidden`, t).slice(0, SHOW_MORE).show();
})
.on('click', hideSelector, function({ delegateTarget: t }) {
$(`${itemSelector}:visible`, t).slice(SHOW_INITIAL).slice(-SHOW_MORE).hide();
})
.each(function() {
$(itemSelector, this).slice(0, SHOW_INITIAL).show();
});