function calculateLapsFromSegmentEfforts(segmentEfforts, numFullLaps = 0) {
  // Get number of lap segments and an array of section segments
  const laps = numFullLaps;
  const sectionsRidden = [];
  segmentEfforts.forEach((effort) => {
    const {
      id: segmentId,
    } = effort.segment;

    if (sectionSegmentIds.indexOf(segmentId) !== -1) {
      // Array of canonical lap section segments
      sectionsRidden.push(segmentId);
    }
  });

  // Remove complete laps from sections ridden
  // OK to stringify since arrays contain only numeric values
  const sectionsRiddenStr = sectionsRidden.join(',');
  const sectionsCanonicalRegex = new RegExp(sectionSegmentIds.join(','), 'g');
  const leftoverSections = sectionsRiddenStr
    .replace(sectionsCanonicalRegex, '')
    .replace(/,{2,}/g, ',')
    .split(',')
    .map((section) => {
      if (section.length && !Number.isNaN(section)) {
        return parseInt(section, 10);
      }
      return 0;
    });


  // Check that laps removed from sections === the number of lap segments
  const removedSections = sectionsRidden.length - leftoverSections.length;
  const removedLaps = removedSections / sectionSegmentIds.length;
  if (removedLaps !== laps) {
    return laps;
  }

  // Are leftover sections enough to add an extra lap?
  if (getUnriddenSections(leftoverSections) <= 1) {
    return laps + 1;
  }

  return laps;
}
/**
 * Logic to calculate number of laps from array of segment efforts
 * Assembles partial laps and combines with received number of
 * canonical (full-lap) segment efforts, assumes these have
 * ALREADY been deduped
 *
 * @param {Array} segmentEfforts All segment efforts
 * @param {Array} numFullLaps Number of deduped full-lap efforts
 * @reutrn {Number}
 */
Logic to calculate number of laps from array of segment efforts
Assembles partial laps and combines with received number of
canonical (full-lap) segment efforts, assumes these have
ALREADY been deduped

@param {Array} segmentEfforts All segment efforts
@param {Array} numFullLaps Number of deduped full-lap efforts
@reutrn {Number}
Logic to calculate number of laps from array of segment efforts Assembles partial laps and combines with received number of canonical ( full - lap ) segment efforts assumes these have ALREADY been deduped @param { Array } segmentEfforts All segment efforts @param { Array } numFullLaps Number of deduped full - lap efforts @reutrn { Number }
function calculateLapsFromSegmentEfforts(segmentEfforts, numFullLaps = 0) {
  const laps = numFullLaps;
  const sectionsRidden = [];
  segmentEfforts.forEach((effort) => {
    const {
      id: segmentId,
    } = effort.segment;
    if (sectionSegmentIds.indexOf(segmentId) !== -1) {
      sectionsRidden.push(segmentId);
    }
  });
  const sectionsRiddenStr = sectionsRidden.join(',');
  const sectionsCanonicalRegex = new RegExp(sectionSegmentIds.join(','), 'g');
  const leftoverSections = sectionsRiddenStr
    .replace(sectionsCanonicalRegex, '')
    .replace(/,{2,}/g, ',')
    .split(',')
    .map((section) => {
      if (section.length && !Number.isNaN(section)) {
        return parseInt(section, 10);
      }
      return 0;
    });
  const removedSections = sectionsRidden.length - leftoverSections.length;
  const removedLaps = removedSections / sectionSegmentIds.length;
  if (removedLaps !== laps) {
    return laps;
  }
  if (getUnriddenSections(leftoverSections) <= 1) {
    return laps + 1;
  }
  return laps;
}
function calculateLapsFromSegmentEfforts ( segmentEfforts , numFullLaps = 0 ) { const laps = numFullLaps ; const sectionsRidden = [ ] ; segmentEfforts . forEach ( ( effort ) => { const { id : segmentId , } = effort . segment ; if ( sectionSegmentIds . indexOf ( segmentId ) !== - 1 ) { sectionsRidden . push ( segmentId ) ; } } ) ; const sectionsRiddenStr = sectionsRidden . join ( ',' ) ; const sectionsCanonicalRegex = new RegExp ( sectionSegmentIds . join ( ',' ) , 'g' ) ; const leftoverSections = sectionsRiddenStr . replace ( sectionsCanonicalRegex , '' ) . replace ( / ,{2,} / g , ',' ) . split ( ',' ) . map ( ( section ) => { if ( section . length && ! Number . isNaN ( section ) ) { return parseInt ( section , 10 ) ; } return 0 ; } ) ; const removedSections = sectionsRidden . length - leftoverSections . length ; const removedLaps = removedSections / sectionSegmentIds . length ; if ( removedLaps !== laps ) { return laps ; } if ( getUnriddenSections ( leftoverSections ) <= 1 ) { return laps + 1 ; } return laps ; }
Logic to calculate number of laps from array of segment efforts
 Assembles partial laps and combines with received number of
 canonical (full-lap) segment efforts, assumes these have
 ALREADY been deduped
Logic to calculate number of laps from array of segment efforts Assembles partial laps and combines with received number of canonical ( full - lap ) segment efforts assumes these have ALREADY been deduped
// Get number of lap segments and an array of section segments // Array of canonical lap section segments // Remove complete laps from sections ridden // OK to stringify since arrays contain only numeric values // Check that laps removed from sections === the number of lap segments // Are leftover sections enough to add an extra lap?