Merge overlapping intervals
How do I make an merge overlapping intervals?
What is a merge overlapping intervals? How do you make a merge overlapping intervals? This script and codes were developed by Berkin on 10 September 2022, Saturday.
Merge overlapping intervals - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Merge overlapping intervals</title>
</head>
<body> <script src="js/index.js"></script>
</body>
</html>
Merge overlapping intervals - Script Codes JS Codes
var temp = [ [900, 1330], [1200, 1530], [1300, 1500], [1430, 1700], [1600, 1700], [1600, 1700], [1400, 1630], [1345, 1400], [1730, 1900], [1930, 2100], [2100, 2200]
]; // The main function that takes a set of intervals, merges // overlapping intervals and prints the result function mergeIntervals(intervals) { // Test if the given set has at least one interval if (intervals.length <= 0) return; // Create an empty stack of intervals var stack = [], last; // sort the intervals based on start time intervals.sort(function(a,b) { return a[0] - b[0]; }); console.log(intervals); // push the first interval to stack stack.push(intervals[0]); // Start from the next interval and merge if necessary for (var i = 1, len = intervals.length ; i < len; i++ ) { // get interval from last item last = stack[stack.length - 1]; // if current interval is not overlapping with stack top, // push it to the stack if (last[1] <= intervals[i][0]) { stack.push( intervals[i] ); } // Otherwise update the ending time of top if ending of current // interval is more else if (last[1] < intervals[i][1]) { last[1] = intervals[i][1]; stack.pop(); stack.push(last); } } console.log(stack); return; } mergeIntervals(temp);
Developer | Berkin |
Username | berkin |
Uploaded | September 10, 2022 |
Rating | 3 |
Size | 1,889 Kb |
Views | 26,312 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
A Pen by berkin | 2,647 Kb |
JQuery UI datepicker with arrow pointing the input | 2,246 Kb |
Tether control | 15,630 Kb |
Slider, flickity | 3,037 Kb |
Javascript - Insertion Sort | 1,501 Kb |
Pull to refresh - hammer.js | 4,903 Kb |
IOS style alphabetic scroll | 3,488 Kb |
Javascript - Merge Sort | 1,509 Kb |
Touch carousel with hammer.js | 14,992 Kb |
CSS switch, works with swipes | 4,825 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Whyutils | LeYvan | 3,752 Kb |
Transitioning application screens with semantically named classes | Djgrant | 3,697 Kb |
Click handler test | Snapson | 2,329 Kb |
This in constructor context | _shree33 | 1,718 Kb |
STIKHOI | Denmch | 7,122 Kb |
Scroll to view if element partially out of view port height | ChrisMaki | 2,104 Kb |
Drifting Clouds | Benedikte | 2,247 Kb |
Commuter Line Tokyu 8500 | Pedox | 7,031 Kb |
Multicolumns 2 | Raphaelgoetter | 1,857 Kb |
Ionic - Wordpress REST API starter | Superpikar | 2,961 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!