function mergeIntervals(intervals) {
intervals = intervals.map(n => [...n]);
if (intervals.length < 2) {
return intervals;
}
intervals.sort((a, b) => a[0] - b[0]);
const stack = [];
intervals.forEach(n => {
const top = stack[stack.length - 1];
if (!top || top[1] < n[0]) {
stack.push(n);
} else if (top[1] < n[1]) {
top[1] = n[1];
}
});
return stack;
}
$groups = [];
foreach ($data as $item) {
$groups[$item['title']][] = $item;
}
echo implode('', array_map(function($group, $title) {
$items = implode('', array_map(function($item) {
$name = $item['name'];
return "<div>$name</div>";
}, $group));
return "<h4>$title:</h4>$items";
}, $groups, array_keys($groups)));
Не могу понять как правильно написать цикл перебора.
$('.hello').attr('data-class', function() {
return [...this.classList].filter(n => n !== 'hello');
});
document.querySelectorAll('.hello').forEach(n => {
n.dataset.class = n.className.replace(/(^| )hello( | $)/, ' ').trim();
});
$('.hello').attr('data-class', function() {
return this.classList[1];
});
document.querySelectorAll('.hello').forEach(n => {
n.dataset.class = n.className.split(' ').pop();
});
Array.prototype.push.apply(
arr,
newArr.filter(n => !arr.some(m => m.trade_id === n.trade_id))
);
const pushDiff = (target, source, key = n => n) =>
target.push(...source.filter(function(n) {
return !this.has(key(n));
}, new Set(target.map(key))));
pushDiff(arr, newArr, n => n.trade_id);
Пробовал через массивы, но не работает.
['negative', '', 'positive'][Math.sign(article.total_comments.length) + 1]
import Vue from 'vue/dist/vue.esm.js'
import Vue from 'vue'
.row {
counter-reset: list -1;
}
.row a::before {
content: counter(list);
counter-increment: list;
}
.row a:first-child::before,
.row a:last-child::before {
content: "";
}
.row {
counter-reset: list 0;
}
.row a:not(:first-child, :last-child)::before {
content: counter(list);
counter-increment: list;
}
const inputSelector = '#kmOutMKAD';
const radioSelector = '[name="delivery"]';
const disabledValue = '1';
$(radioSelector).on('change', function() {
$(inputSelector).prop('disabled', this.value === disabledValue);
});
// или
const input = document.querySelector(inputSelector);
const radios = document.querySelectorAll(radioSelector);
const onChange = e => input.disabled = e.target.value === disabledValue;
radios.forEach(n => n.addEventListener('change', onChange));