function search(nums, target, searchMin) {
for (let iMin = 0, iMax = nums.length - 1; iMin <= iMax; ) {
const index = (iMin + iMax) / 2 | 0;
const num = nums[index];
if (num === target && num !== nums[index + (searchMin ? -1 : 1)]) {
return index;
} else if (num <= target - (searchMin ? 1 : 0)) {
iMin = index + 1;
} else {
iMax = index - 1;
}
}
return -1;
}
function searchMinMax(nums, target) {
const iMin = search(nums, target, true);
return iMin === -1
? []
: [ iMin, search(nums, target, false) ];
}
@update:modelValue="$emit('change', $event.target.value)"
update:modelValue
?@change="$emit('update:modelValue', $event.target.value)"
model: { prop: 'modelValue', event: 'update:modelValue' },
BREAKING:v-bind
's.sync
modifier and componentmodel
option are removed and replaced with an argument on v-model;
.filter(function (el, i) { return arr[i] === el[i]; })
0
? Или 5
? А зачем тогда [i]
? Может, должно было быть arr[i] === el
? const dashoffset = circleRef.current - ...
NaN
.const getSctollTop = () => { return window.pageYOffset || document.documentElement.scrollTo; }
scrollTo
? Это же метод, а вы вроде бы число хотите получить. Может, scrollTop
?React.useEffect(() => { ... window.addEventListener("scroll", () => { ... }); }, []);
Как должен выглядеть json...
[
{
title: '...',
children: [
{
title: '...',
children: [
{
title: '...',
},
...
],
},
...
],
},
...
]
...для генерации такого вложенного списка через v-for?
name: 'v-tree',
props: [ 'items' ],
<ul v-if="Array.isArray(items) && items.length">
<li v-for="n in items">
{{ n.title }}
<v-tree :items="n.children" />
</li>
</ul>
const popup =createApp(App);
popup.$store.dispatch
$store
, вам нужен результат вызова mount
, а не createApp
.store.dispatch
. const searchOptions = [
[ '#search_table', tr => $('input[name^=name]', tr).val() ],
[ '#search_card', tr => $('[data-item-name="name"]', tr).text() ]
];
$(searchOptions.map(n => n[0]).join(', ')).on('input', () => {
const values = searchOptions.map(n => $(n[0]).val().toLowerCase());
$('#tabname tbody tr')
.hide()
.filter((i, n) => searchOptions.every((m, j) => m[1](n).toLowerCase().includes(values[j])))
.show();
});
const sorted = (arr, key) => arr
.map(n => [ key(n), n ])
.sort(([a], [b]) => a < b ? -1 : +(a > b))
.map(n => n[1]);
const sortedArr = sorted(arr, n => new Date(n.replace(/(\d+)\.(\d+)\.(\d+),/, '$3-$2-$1')));
// или
const sortedArr = sorted(arr, n => n.replace(/.+(?=,)/, m => m.split('.').reverse().join('')));
`${arr}`.match(/\b\w{5}\b/g) || []
// или
arr.reduce((acc, n) => (n.length ^ '0b101' || acc.push(n), acc), [])
// или
arr.filter(n => n[4] && !n[-~4])
// или
arr.filter(RegExp.prototype.test.bind(/^.....$/))
// или
arr.reduce((acc, n) => ((acc[n.search('$')] ??= []).push(n), acc), {})[5] ?? []
// или
(function xxx(arr, i = 0) {
return arr.hasOwnProperty(i)
? [].concat(5 - [].push(...arr[i]) ? [] : arr[i], xxx(arr, i + 1))
: [];
})(arr)
instanceof Object
.true
или false
.function getNestedData(data, test) {
const result = [];
for (const stack = [ data ]; stack.length;) {
const n = stack.pop();
if (n instanceof Object) {
stack.push(...Object.values(n).reverse());
}
if (test(n)) {
result.push(n);
}
}
return result;
}
console.log(getNestedData(tree, Number.isFinite));
computed: {
bullshitEmails() {
const search = this.search.trim().toLowerCase();
return this.emails.map(n => ({
email: n,
marked: !!search && n.toLowerCase().includes(search),
}));
},
},
<ul>
<li
v-for="{ email, marked } in bullshitEmails"
v-text="email"
:class="{ marked }"
></li>
</ul>
arr = [ '3.1', '5.1', '1.3', '2.2', '13.3' ]
num = '5.666'
print('OK' if any(n.split('.')[0] == num.split('.')[0] for n in arr) else 'FUCK OFF')
const firstNonRepeatingLetter = ([...str]) => Object
.values(str.reduce((acc, n, i) => ((acc[n.toLowerCase()] ??= [ 0, i, n ])[0]++, acc), {}))
.reduce((min, n) => (n[0] === 1 && n[1] < min[1] ? n : min), [ 0, Infinity, '' ])
.pop();
const firstNonRepeatingLetter = str =>
str.charAt(Array
.from(str.toLowerCase())
.findIndex((n, i, a) => a.indexOf(n) === a.lastIndexOf(n))
);
async function() {
let result = null;
while (1) {
result = await fetch(...);
if (result тот, который нужен) {
break;
}
await new Promise(r => setTimeout(r, 5000));
}
return result;
}