<commit_before>import { getKeyForAddresses } from './helpers';

export function getLocations( state ) {
  return state.library.locations;
}

export function getLocationById( state, id ) {
  return getLocations( state ).reduce( ( found, location ) => {
    if ( location._id === id ) return location;
    return found;
  }, null );
}

export function getLocationsForTrip( state ) {
  return state.trip.map( id => getLocationById( state, id ) );
}

export function getAddressesForTrip( state ) {
  return getLocationsForTrip( state )
  .map( location => location.address );
}

export function getAddressPairs( state ) {
  const addrs = getAddressesForTrip( state );
  return addrs.reduce( ( pairs, start, index ) => {
    const dest = addrs[ index + 1 ];
    return dest ? pairs.concat( { start, dest } ) : pairs;
  }, [] );
}

export function getTripDistances( state ) {
  const pairs = getAddressPairs( state );
  return pairs.map( pair => getDistanceForKey( state, getKeyForAddresses( pair.start, pair.dest ) ) );
}

export function getTotalTripDistance( state ) {
  return getTripDistances( state ).reduce( ( prev, num ) => prev + num, 0 );
}

export function getDistanceForKey( state, key ) {
  return state.distances[ key ];
}
<commit_msg>Hide locations for trip which have no matching location<commit_after>import { getKeyForAddresses } from './helpers';

export function getLocations( state ) {
  return state.library.locations;
}

export function getLocationById( state, id ) {
  return getLocations( state ).reduce( ( found, location ) => {
    if ( location._id === id ) return location;
    return found;
  }, null );
}

export function getLocationsForTrip( state ) {
  return state.trip.map( id => getLocationById( state, id ) )
  .filter( location => !! location );
}

export function getAddressesForTrip( state ) {
  return getLocationsForTrip( state )
  .map( location => location.address );
}

export function getAddressPairs( state ) {
  const addrs = getAddressesForTrip( state );
  return addrs.reduce( ( pairs, start, index ) => {
    const dest = addrs[ index + 1 ];
    return dest ? pairs.concat( { start, dest } ) : pairs;
  }, [] );
}

export function getTripDistances( state ) {
  const pairs = getAddressPairs( state );
  return pairs.map( pair => getDistanceForKey( state, getKeyForAddresses( pair.start, pair.dest ) ) );
}

export function getTotalTripDistance( state ) {
  return getTripDistances( state ).reduce( ( prev, num ) => prev + num, 0 );
}

export function getDistanceForKey( state, key ) {
  return state.distances[ key ];
}

{'fraction_non_alphanumeric': 0.12436647173489279, 'fraction_numerical': 0.0015594541910331384, 'mean_word_length': 4.01171875, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5589665', 'n_tokens_mistral': 787, 'n_tokens_neox': 780, 'n_words': 231}