[php] Globtesrt

Viewer

copydownloadembedprintName: Globtesrt
  1. <?php 
  2. $var = 'function foo(intervals) {
  3.   if (intervals.length === 1) return intervals;
  4.   intervals.sort((a, b) => a[0] - b[0]);
  5.   let current = intervals[0];
  6.   const result = [current];
  7.   for (let i = 1; i < intervals.length; i += 1) {
  8.     const currentRight = current[1];
  9.     const [nextLeft, nextRight] = intervals[i];
  10.     if (currentRight >= nextLeft) {
  11.       current[1] = Math.max(currentRight, nextRight);
  12.     } else {
  13.       result.push(intervals[i]);
  14.       current = intervals[i];
  15.     }
  16.   }
  17.   return result;
  18. }';

Editor

You can edit this paste and save as new:


File Description
  • Globtesrt
  • Paste Code
  • 10 Aug-2022
  • 536 Bytes
You can Share it: