index.js
// This function compares two endpoints, checks which shared key they have and returns them, also returns the data from the endpoints to work with later on
This function compares two endpoints, checks which shared key they have and returns them, also returns the data from the endpoints to work with later on
This function compares two endpoints checks which shared key they have and returns them also returns the data from the endpoints to work with later on
function sharedIds(endpointA, endpointB, sharedKey) {
  const resultA = getData(endpointA)
  const resultB = getData(endpointB)
  let idsA = [];
  let sharedIds = [];
  return Promise.all([resultA, resultB]).then(result => {
    idsA = result[0].map(x => x[sharedKey]) 
    sharedIds = result[1].filter(x => idsA.includes(x[sharedKey])).map(x => x[sharedKey]) 
    sharedIds = sharedIds.filter((item, pos) => { 
      return sharedIds.indexOf(item) == pos;
    })
    return {
      sharedIds: sharedIds,
      resultA: result[0],
      resultB: result[1]
    }
  })
}
function sharedIds ( endpointA , endpointB , sharedKey ) { const resultA = getData ( endpointA ) const resultB = getData ( endpointB ) let idsA = [ ] ; let sharedIds = [ ] ; return Promise . all ( [ resultA , resultB ] ) . then ( result => { idsA = result [ 0 ] . map ( x => x [ sharedKey ] ) sharedIds = result [ 1 ] . filter ( x => idsA . includes ( x [ sharedKey ] ) ) . map ( x => x [ sharedKey ] ) sharedIds = sharedIds . filter ( ( item , pos ) => { return sharedIds . indexOf ( item ) == pos ; } ) return { sharedIds : sharedIds , resultA : result [ 0 ] , resultB : result [ 1 ] } } ) }
This function compares two endpoints, checks which shared key they have and returns them, also returns the data from the endpoints to work with later on
This function compares two endpoints checks which shared key they have and returns them also returns the data from the endpoints to work with later on
// Here the keys will be mapped in an array // Here the shared keys get filtered, compared and mapped out of the second result // This removes duplicate values from the array https://stackoverflow.com/questions/9229645/remove-duplicate-values-from-js-array