const isSingleInterval = (intervals) => {
const sortedIntervals = intervals.sort(([a], [b]) => a - b);
const [first, ...rest] = sortedIntervals;
const mergedIntervals = [first];
rest.forEach((element) => {
const current = mergedIntervals[mergedIntervals.length - 1];
if (element[0] <= current[1]) {
current[1] = Math.max(current[1], element[1]);
} else {
mergedIntervals.push(element);
}
});
return mergedIntervals.length === 1;
};