1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-15 23:00:36 +02:00

Desktop: Resolves #2683: Go To Anything by body (#2686)

* Go to anything by body

* Made limit parameter required

* Made parameter required

Co-authored-by: Laurent Cozic <laurent22@users.noreply.github.com>
This commit is contained in:
Anjula Karunarathne
2020-03-28 13:05:00 +00:00
committed by GitHub
parent d54e52b1a8
commit a45128807e
5 changed files with 150 additions and 11 deletions

View File

@ -58,4 +58,26 @@ ArrayUtils.contentEquals = function(array1, array2) {
return true;
};
// Merges multiple overlapping intervals into a single interval
// e.g. [0, 25], [20, 50], [75, 100] --> [0, 50], [75, 100]
ArrayUtils.mergeOverlappingIntervals = function(intervals, limit) {
intervals.sort((a, b) => a[0] - b[0]);
const stack = [];
if (intervals.length) {
stack.push(intervals[0]);
for (let i = 1; i < intervals.length && stack.length < limit; i++) {
const top = stack[stack.length - 1];
if (top[1] < intervals[i][0]) {
stack.push(intervals[i]);
} else if (top[1] < intervals[i][1]) {
top[1] = intervals[i][1];
stack.pop();
stack.push(top);
}
}
}
return stack;
};
module.exports = ArrayUtils;