const runTasks = (tasks, max = 1) =>
new Promise(resolve => {
const results = Array(tasks.length).fill(null);
let started = 0;
let finished = 0;
for (let i = Math.max(1, Math.min(max, tasks.length)); i--; run()) ;
async function run() {
if (finished === tasks.length) {
resolve(results);
} else if (started < tasks.length) {
const index = started++;
try {
results[index] = await tasks[index]();
} catch (e) {
results[index] = e;
}
finished++;
run();
}
}
});
const sendRequests = (urls, ...args) =>
runTasks(urls.map(n => () => fetch(n).then(r => r.json())), ...args);
const printf = (str, ...params) =>
str.replace(/\$(\d+)/g, (m, g1) => params[~-g1] ?? m);
массивСДанными.map((n, i) => {
const Component = i % через_сколько_там_надо_чередовать_компоненты
? КомпонентРаз
: КомпонентДва;
return <Component {...n} />;
})
.item:nth-child(2n) {
background-color: red;
}<div v-for="n in items" class="item"><div v-for="(n, i) in items" :style="i & 1 && { backgroundColor: 'red' }">
strval(intval($str))preg_replace('~^0+~', '', $str)
Я новичок в python
if change_index <= len(alphabet): result_text += alphabet[change_index]
function Ranges(props) {
const onChange = ({ target: t }) => {
const index = +t.dataset.index;
const value = +t.value;
const values = props.values.map((n, i) => i === index ? value : n);
if (props.max >= values.reduce((acc, n) => acc + n, 0)) {
props.onChange(values);
}
};
return (
<div>
{props.values.map((n, i) => (
<div>
<input
type="range"
data-index={i}
max={props.max}
value={n}
onChange={onChange}
/>
{n}
</div>
))}
</div>
);
}
const groupedAndSortedArr = Object
.values(arr.reduce((acc, n) => ((acc[n[0]] ??= []).push(n), acc), {}))
.sort((a, b) => a[0][0].localeCompare(b[0][0]));
str.split('=').pop()
// или
str.slice(str.indexOf('=') + 1)str.replace(/[^=]*=/, '')
// или
str.match(/(?<==).*/)[0]
// или
/[^=]*$/.exec(str).shift()new URLSearchParams(str).get('sort')
const obj = [...str.matchAll(/([^?&]+)=([^&]+)/g)]
.reduce((acc, [ , k, v ]) => (
k.endsWith('[]')
? (acc[k.slice(0, -2)] ??= []).push(v)
: acc[k] = v,
acc
), {});const params = new URLSearchParams(str);
const reg = /\[\]$/;
const obj = Object.fromEntries(Array.from(
new Set(params.keys()),
n => [
n.replace(reg, ''),
params[reg.test(n) ? 'getAll' : 'get'](n),
]
));const obj = str.split('?').pop().split('&').reduce((acc, n) => {
let [ k, v ] = n.split('=');
const isArr = k.slice(-2) === '[]';
k = k.substring(0, k.length - isArr * 2);
const target = (isArr ? (acc[k] = acc[k] || []) : acc);
target[isArr ? target.length : k] = v;
return acc;
}, {});
Как правило, все плагины работают от обратного - у них есть возможность передать массив только с неактивными датами.
config.enable.дата => массив.includes(дата.toLocaleDateString()):disbaledDates.customPredictor.beforeShowDay.
$grouped = [];
foreach ($arr as $n) {
$grouped[$n['category_id']][] = $n['text'];
}
foreach ($grouped as $key => $values) {
echo "
<fieldset>
<legend>$key</legend>".
implode('', array_map(fn($n) => "<div>$n</div>", $values))."
</fieldset>";
}