lessThan

lessThan

  • (right: number) => (left: number) => number
  1. Test whether a number is less than another

    const lt2 = lessThan(2)
    lt2(1) // is true
    lt2(2) // is false
    const lt2 = lessThan(2)
    lt2(1) // is true
    lt2(2) // is false
    
    const lt2 = lessThan(2)
    lt2(1) // is true
    lt2(2) // is false
    const lt2 = lessThan(2)
    lt2(1) // is true
    lt2(2) // is false
    
  2. Sometimes we want to test for thresholds. Below, we run a scooter company. Users rate the scooters after use, allowing us to inspect those that don't operate smoothly. Let's get the scooters that are rated less than 4 stars.

    const scooterRatings = {
      s52: 3.4,
      s14: 4.0,
      s67: 3.8,
    }
    
    const lessThan4Stars = lessThan(4)
    const getScootersToInspect = compose([keepWhen(lessThan4Stars), Object.keys])
    
    const scooterIds = getScootersToInspect(scooterRatings)
    console.log(scooterIds)
    // [
    //   s52
    //   s67
    // ]
    type Ratings = Record<string, number>
    const scooterRatings: Ratings = {
      s52: 3.4,
      s14: 4.0,
      s67: 3.8,
    }
    
    const lessThan4Stars = lessThan(4)
    const getScootersToInspect = compose([
      keepWhen(lessThan4Stars)<Ratings>,
      Object.keys,
    ])
    
    const scooterIds = getScootersToInspect(scooterRatings)
    console.log(scooterIds)
    // [
    //   s52
    //   s67
    // ]
    
    const scooterRatings = {
      s52: 3.4,
      s14: 4.0,
      s67: 3.8,
    }
    
    const lessThan4Stars = lessThan(4)
    const getScootersToInspect = compose([
      keepWhen(lessThan4Stars),
      Object.keys,
    ])
    
    const scooterIds = getScootersToInspect(
      scooterRatings
    )
    console.log(scooterIds)
    // [
    //   s52
    //   s67
    // ]
    type Ratings = Record<string, number>
    const scooterRatings: Ratings = {
      s52: 3.4,
      s14: 4.0,
      s67: 3.8,
    }
    
    const lessThan4Stars = lessThan(4)
    const getScootersToInspect = compose([
      keepWhen(lessThan4Stars)<Ratings>,
      Object.keys,
    ])
    
    const scooterIds = getScootersToInspect(
      scooterRatings
    )
    console.log(scooterIds)
    // [
    //   s52
    //   s67
    // ]