Nancy's Preferred Machete

    segflip

    0.0.2 • Public • Published

    segflip

    Flip the Inside and Outside of Segments on a Single-Dimensional Integer Line

    install

    command line

    npm install segflip

    browser

    <script src="https://unpkg.com/segflip"></script>

    usage

    import segflip from "segflip";
    
    // 21st century recessions in the United States
    // from https://en.wikipedia.org/wiki/List_of_recessions_in_the_United_States
    const recessions = [
      [2001, 2001], // Early 2000s recession
      [2007, 2009], // Great Recession
      [2020, 2020] // COVID-19 recession
    ];
    
    const results = segflip({
      segments: recessions,
      
      // smallest possible integer
      // default is -Infinity
      min: 2000,
      
      // largest possible integer
      // default is Infinity
      max: 2022
    });

    results is an array of year ranges when there wasn't a recession

    [
      [2000, 2000],
      [2002, 2006],
      [2010, 2019],
      [2021, 2022]
    ]

    Install

    npm i segflip

    DownloadsWeekly Downloads

    1,069

    Version

    0.0.2

    License

    CC0-1.0

    Unpacked Size

    9.9 kB

    Total Files

    4

    Last publish

    Collaborators

    • danieljdufour