function calculateLapsFromDefinitions(efforts, locConfig) {
  // Segment IDs corresponding to segment efforts
  const effortsSegmentIds = efforts.map((eff) => eff.segment.id);
  const {
    lapDefinitions = [],
  } = locConfig;

  if (!lapDefinitions.length) {
    return 0;
  }

  // Array of segment IDs which are the start of a definition set
  const definitionStartIds = [];
  // Map of start segments to definition sets
  const definitionSetsMap = {};
  lapDefinitions.forEach((bounds) => {
    definitionStartIds.push(bounds[0]);
    definitionSetsMap[bounds[0]] = bounds;
  });

  // Find the start segment that appears first
  // Assumes start segments are unique!!
  const firstOccurringId = _find(
    effortsSegmentIds,
    (id) => definitionStartIds.indexOf(id) !== -1,
  );

  // Filter for identified definition set
  const definitionSet = definitionSetsMap[firstOccurringId];
  const filteredSegmentIds = effortsSegmentIds.filter(
    (id) => definitionSet.indexOf(id) !== -1,
  );
  return countFilteredLaps(filteredSegmentIds, definitionSet);
}
/**
 * Calculate laps using new lapDefinitions technique
 * REQUIRES a unique start segment for each definition set
 *
 * @param {Array} efforts Segment Efforts for lapDefinitions
 * @param {Object} locConfig Config object for location
 * @returns {Number}
 */
Calculate laps using new lapDefinitions technique
REQUIRES a unique start segment for each definition set

@param {Array} efforts Segment Efforts for lapDefinitions
@param {Object} locConfig Config object for location
@returns {Number}
Calculate laps using new lapDefinitions technique REQUIRES a unique start segment for each definition set @param { Array } efforts Segment Efforts for lapDefinitions @param { Object } locConfig Config object for location @returns { Number }
function calculateLapsFromDefinitions(efforts, locConfig) {
  const effortsSegmentIds = efforts.map((eff) => eff.segment.id);
  const {
    lapDefinitions = [],
  } = locConfig;
  if (!lapDefinitions.length) {
    return 0;
  }
  const definitionStartIds = [];
  const definitionSetsMap = {};
  lapDefinitions.forEach((bounds) => {
    definitionStartIds.push(bounds[0]);
    definitionSetsMap[bounds[0]] = bounds;
  });
  const firstOccurringId = _find(
    effortsSegmentIds,
    (id) => definitionStartIds.indexOf(id) !== -1,
  );
  const definitionSet = definitionSetsMap[firstOccurringId];
  const filteredSegmentIds = effortsSegmentIds.filter(
    (id) => definitionSet.indexOf(id) !== -1,
  );
  return countFilteredLaps(filteredSegmentIds, definitionSet);
}
function calculateLapsFromDefinitions ( efforts , locConfig ) { const effortsSegmentIds = efforts . map ( ( eff ) => eff . segment . id ) ; const { lapDefinitions = [ ] , } = locConfig ; if ( ! lapDefinitions . length ) { return 0 ; } const definitionStartIds = [ ] ; const definitionSetsMap = { } ; lapDefinitions . forEach ( ( bounds ) => { definitionStartIds . push ( bounds [ 0 ] ) ; definitionSetsMap [ bounds [ 0 ] ] = bounds ; } ) ; const firstOccurringId = _find ( effortsSegmentIds , ( id ) => definitionStartIds . indexOf ( id ) !== - 1 , ) ; const definitionSet = definitionSetsMap [ firstOccurringId ] ; const filteredSegmentIds = effortsSegmentIds . filter ( ( id ) => definitionSet . indexOf ( id ) !== - 1 , ) ; return countFilteredLaps ( filteredSegmentIds , definitionSet ) ; }
Calculate laps using new lapDefinitions technique
 REQUIRES a unique start segment for each definition set
Calculate laps using new lapDefinitions technique REQUIRES a unique start segment for each definition set
// Segment IDs corresponding to segment efforts // Array of segment IDs which are the start of a definition set // Map of start segments to definition sets // Find the start segment that appears first // Assumes start segments are unique!! // Filter for identified definition set