containedIn

containedIn

  • (collection: string) => (value: string) => boolean
    Or
  • (collection: Collection) => (value: any) => boolean
  1. Test if a value is contained in a collection

    const containedInAB = containedIn(['a', 'b'])
    
    containedInAB('a') // is true
    containedInAB('c') // is false
    const containedInAB = containedIn(['a', 'b'])
    
    containedInAB('a') // is true
    containedInAB('c') // is false
    
    const containedInAB = containedIn(['a', 'b'])
    
    containedInAB('a') // is true
    containedInAB('c') // is false
    const containedInAB = containedIn(['a', 'b'])
    
    containedInAB('a') // is true
    containedInAB('c') // is false
    
  2. We often want to see if a value is in a collection. Below, we see if a student is in the classroom.

    const studentsInClass = ['meg', 'tom', 'ken']
    const isPresent = containedIn(studentsInClass)
    
    isPresent('meg') // is true
    isPresent('chris') // is false
    const studentsInClass = ['meg', 'tom', 'ken']
    const isPresent = containedIn(studentsInClass)
    
    isPresent('meg') // is true
    isPresent('chris') // is false
    
    const studentsInClass = ['meg', 'tom', 'ken']
    const isPresent = containedIn(studentsInClass)
    
    isPresent('meg') // is true
    isPresent('chris') // is false
    const studentsInClass = ['meg', 'tom', 'ken']
    const isPresent = containedIn(studentsInClass)
    
    isPresent('meg') // is true
    isPresent('chris') // is false