getExclusiveValues

getExclusiveValues

  • (anArray: ValueCollection[]) => array
  1. Return the values exclusively in one collection

    const result = getExclusiveValues([
      ['a', 'b'],
      ['b', 'c'],
    ])
    console.log(result) // is ['a', 'c']
    const result = getExclusiveValues([
      ['a', 'b'],
      ['b', 'c'],
    ])
    console.log(result) // is ['a', 'c']
    
    const result = getExclusiveValues([
      ['a', 'b'],
      ['b', 'c'],
    ])
    console.log(result) // is ['a', 'c']
    const result = getExclusiveValues([
      ['a', 'b'],
      ['b', 'c'],
    ])
    console.log(result) // is ['a', 'c']
    
  2. Sometimes we have a list of grouped values and only want those that appear in a single group. Below, we work for a dating app and are figuring out how many people are in a single relationship. Let's find out.

    const relationships = [
      ['mary', 'sarah'],
      ['matt', 'jason'],
      ['amy', 'kim'],
      ['mary', 'matt'],
      ['jason', 'kim'],
    ]
    
    const peopleInOneRelationship = getExclusiveValues(relationships)
    console.log(peopleInOneRelationship)
    // is [
    //   sarah,
    //   amy,
    // ]
    const relationships = [
      ['mary', 'sarah'],
      ['matt', 'jason'],
      ['amy', 'kim'],
      ['mary', 'matt'],
      ['jason', 'kim'],
    ]
    
    const peopleInOneRelationship = getExclusiveValues(relationships)
    console.log(peopleInOneRelationship)
    // is [
    //   sarah,
    //   amy,
    // ]
    
    const relationships = [
      ['mary', 'sarah'],
      ['matt', 'jason'],
      ['amy', 'kim'],
      ['mary', 'matt'],
      ['jason', 'kim'],
    ]
    
    const peopleInOneRelationship =
      getExclusiveValues(relationships)
    console.log(peopleInOneRelationship)
    // is [
    //   sarah,
    //   amy,
    // ]
    const relationships = [
      ['mary', 'sarah'],
      ['matt', 'jason'],
      ['amy', 'kim'],
      ['mary', 'matt'],
      ['jason', 'kim'],
    ]
    
    const peopleInOneRelationship =
      getExclusiveValues(relationships)
    console.log(peopleInOneRelationship)
    // is [
    //   sarah,
    //   amy,
    // ]