function munge(bookMatches) {
  let keyLength = keyInfo.getKeyInfo().keyLength;
  let combined = [];
  let count = 0;

  for (const match of bookMatches) {
    if (!combined[count]) {
      combined[count] = {
        unit: match.unit,
        book: match.book,
        pageKey: match.key.substr(0, keyLength),
        m: [{location: match.location, context: match.context}]
      };
    }
    else if (combined[count].unit !== match.unit) {
      count++;
      combined[count] = {
        unit: match.unit,
        book: match.book,
        pageKey: match.key.substr(0, keyLength),
        m: [{location: match.location, context: match.context}]
      };
    }
    else {
      combined[count].m.push({location: match.location, context: match.context});
    }
  }
  return combined;
}
/*
  for a given page, combine all matches into an array
*/
for a given page, combine all matches into an array
for a given page combine all matches into an array
function munge(bookMatches) {
  let keyLength = keyInfo.getKeyInfo().keyLength;
  let combined = [];
  let count = 0;
  for (const match of bookMatches) {
    if (!combined[count]) {
      combined[count] = {
        unit: match.unit,
        book: match.book,
        pageKey: match.key.substr(0, keyLength),
        m: [{location: match.location, context: match.context}]
      };
    }
    else if (combined[count].unit !== match.unit) {
      count++;
      combined[count] = {
        unit: match.unit,
        book: match.book,
        pageKey: match.key.substr(0, keyLength),
        m: [{location: match.location, context: match.context}]
      };
    }
    else {
      combined[count].m.push({location: match.location, context: match.context});
    }
  }
  return combined;
}
function munge ( bookMatches ) { let keyLength = keyInfo . getKeyInfo ( ) . keyLength ; let combined = [ ] ; let count = 0 ; for ( const match of bookMatches ) { if ( ! combined [ count ] ) { combined [ count ] = { unit : match . unit , book : match . book , pageKey : match . key . substr ( 0 , keyLength ) , m : [ { location : match . location , context : match . context } ] } ; } else if ( combined [ count ] . unit !== match . unit ) { count ++ ; combined [ count ] = { unit : match . unit , book : match . book , pageKey : match . key . substr ( 0 , keyLength ) , m : [ { location : match . location , context : match . context } ] } ; } else { combined [ count ] . m . push ( { location : match . location , context : match . context } ) ; } } return combined ; }
for a given page, combine all matches into an array
for a given page combine all matches into an array