function calculateLapsFromSegmentEfforts(
  allEfforts,
  numCanonicalLaps,
  segmentId,
) {
  let numFoundLaps = 0;
  // Array of section efforts before the first and after the last canonical lap
  const partialLapEfforts = [];
  allEfforts.forEach((effort) => {
    if (effort.segment.id === segmentId) {
      numFoundLaps += 1;
      return;
    }
    if (numFoundLaps === 0 || numFoundLaps === numCanonicalLaps) {
      partialLapEfforts.push(effort);
    }
  });

  const sectionSegmentIdsStr = partialLapEfforts
    .reduce((acc, { segment }) => acc + segment.id, '');

  // Get sequences strings like ['123', '234', '341', '412']
  // from set of segment ids like [1,2,3,4]
  // leave off last segment to simulate enter/exit skipping a segment
  const possibleSectionSequences = getSegmentSequences(segmentId)
    .map((sequence) => sequence.join(''));

  // If any of the sequence strings are found the string representing
  // all the partial lap segments before first and after last full lap
  // Count it as a lap
  for (let idx = 0; idx < possibleSectionSequences.length; idx += 1) {
    if (sectionSegmentIdsStr.indexOf(possibleSectionSequences[idx]) > -1) {
      return numCanonicalLaps + 1;
    }
  }
  return numCanonicalLaps;
}
/**
 * Calculate number of laps by assembling partial lap before/after full laps
 * uses original sectionSegmentIds method
 *
 * @param {Array} allEfforts Array of all relevant segment efforts for this location
 * @param {Number} numCanonicalLaps Number of numCanonicalLaps we already know about
 * @param {Number} segmentId ID of canonical segment we're building around
 * @returns {Number} Number of laps from this activity for a single location
 */
Calculate number of laps by assembling partial lap before/after full laps
uses original sectionSegmentIds method

@param {Array} allEfforts Array of all relevant segment efforts for this location
@param {Number} numCanonicalLaps Number of numCanonicalLaps we already know about
@param {Number} segmentId ID of canonical segment we're building around
@returns {Number} Number of laps from this activity for a single location
Calculate number of laps by assembling partial lap before / after full laps uses original sectionSegmentIds method @param { Array } allEfforts Array of all relevant segment efforts for this location @param { Number } numCanonicalLaps Number of numCanonicalLaps we already know about @param { Number } segmentId ID of canonical segment we ' re building around @returns { Number } Number of laps from this activity for a single location
function calculateLapsFromSegmentEfforts(
  allEfforts,
  numCanonicalLaps,
  segmentId,
) {
  let numFoundLaps = 0;
  const partialLapEfforts = [];
  allEfforts.forEach((effort) => {
    if (effort.segment.id === segmentId) {
      numFoundLaps += 1;
      return;
    }
    if (numFoundLaps === 0 || numFoundLaps === numCanonicalLaps) {
      partialLapEfforts.push(effort);
    }
  });
  const sectionSegmentIdsStr = partialLapEfforts
    .reduce((acc, { segment }) => acc + segment.id, '');
  const possibleSectionSequences = getSegmentSequences(segmentId)
    .map((sequence) => sequence.join(''));
  for (let idx = 0; idx < possibleSectionSequences.length; idx += 1) {
    if (sectionSegmentIdsStr.indexOf(possibleSectionSequences[idx]) > -1) {
      return numCanonicalLaps + 1;
    }
  }
  return numCanonicalLaps;
}
function calculateLapsFromSegmentEfforts ( allEfforts , numCanonicalLaps , segmentId , ) { let numFoundLaps = 0 ; const partialLapEfforts = [ ] ; allEfforts . forEach ( ( effort ) => { if ( effort . segment . id === segmentId ) { numFoundLaps += 1 ; return ; } if ( numFoundLaps === 0 || numFoundLaps === numCanonicalLaps ) { partialLapEfforts . push ( effort ) ; } } ) ; const sectionSegmentIdsStr = partialLapEfforts . reduce ( ( acc , { segment } ) => acc + segment . id , '' ) ; const possibleSectionSequences = getSegmentSequences ( segmentId ) . map ( ( sequence ) => sequence . join ( '' ) ) ; for ( let idx = 0 ; idx < possibleSectionSequences . length ; idx += 1 ) { if ( sectionSegmentIdsStr . indexOf ( possibleSectionSequences [ idx ] ) > - 1 ) { return numCanonicalLaps + 1 ; } } return numCanonicalLaps ; }
Calculate number of laps by assembling partial lap before/after full laps
 uses original sectionSegmentIds method
Calculate number of laps by assembling partial lap before / after full laps uses original sectionSegmentIds method
// Array of section efforts before the first and after the last canonical lap // Get sequences strings like ['123', '234', '341', '412'] // from set of segment ids like [1,2,3,4] // leave off last segment to simulate enter/exit skipping a segment // If any of the sequence strings are found the string representing // all the partial lap segments before first and after last full lap // Count it as a lap