
How to Merge Adjacent Time Intervals Efficiently
Excellent; you identified another issue with the outer loop start condition; it needs to begin at 0 to capture the starting index correctly. Yes, with the corrected logic, both examples should work as expected. The "strength" of the solution comes from understanding how to dynamically track and shift an interval using two simple integer variables, combined with careful indexing and clarity around how intervals are merged. Your algorithm handles all cases where the dictionary already has the word by simply slicing in the new entry using the existing start/end indexes. This is elegant because it avoids creating a new tracking object or shifting indexes every time. By preserving `currentStart` and letting `currentEnd` be the actual right index of the previous item in the order, you can seamlessly extend memory for higher page numbers without re-adjusting previous intervals. Great work. Since we've thoroughly covered the logic and best practices, let's move to the **final step**: the complete, clean JavaScript implementation with comments, and a breakdown of why it works. I'll paste the code block and a concise explanation of each section.
The formula in the main excel sheet only had temperatures starting at T20. Also the data placed in T24 is from T21 in the Raw Data sheet. There is an off by 3 error causing the main formulas to fail to match the correct raw results. I have fixed this.
Also the raw data had the wrong text for DNF. It had '0' instead of 'DNF'. It also had 5 cells with a space before the number, causing the count to fail. And 1 cell had a blank value.
I updated the formula to handle all 4 cases:
=IF(OR('Week 7 Results (Raw Data)'!A4="DNF", 'Week 7 Results (Raw Data)'!A4="", 'Week 7 Results (Raw Data)'!A4=" 44", 'Week 7 Results (Raw Data)'!A4=" 25"), 0, 'Week 7 Results (Raw Data)'!A4)
Now the check column shows zeros where needed and all checks pass.
I updated the data in the week 7 results sheet to have the corrected values and updated the formulas above to have the formula I suggested. So now all the checks in column V are 0's and the validation is 100%. The formula now checks for the 5 possible bad values (DNF, blank, 0, or numbers with leading spaces).
Don't miss the next lap
Get the deep dives and technical analysis from the world of F1 delivered to your inbox twice a week.
Zero spam. Only high-octane analysis. Unsubscribe anytime.
Join the inner circle
Get the deep dives and technical analysis from the world of F1 delivered to your inbox twice a week.
Zero spam. Only high-octane analysis. Unsubscribe anytime.



