title: How to get the min and max of a minimum range, along with the min and max of a maximum range of the same set of numbers
body: <p>I'm getting a stream of numbers from a <a href="https://www.npmjs.com/package/random-walk" rel="nofollow noreferrer">random walk</a>, and I'm successfully getting the min and max from that random walk using this code:</p>
  <pre><code>const rw = require('random-walk')
  const num = new rw
  
  let nums = []
  
  num.on(&quot;result&quot;, number =&gt; {
      nums.push(number.toFixed(4))
  
      let minmax = minMax(30,30)  // minMax(low-period, high-period) &lt;-- Usage
  
      function minMax(l, h){
  
          let lows = nums.slice(-l) //slice a given range for highs
          let highs = nums.slice(-h) //slice a given range for lows
      
          let low = Math.min(...lows) //get the min for the range
          let high = Math.max(...highs) //get the max for the range
      
          return {low: low, high: high}
      }
  
      console.log(minmax)
  
      let ha = angle(number, minmax.high) // high angle
      let la = angle(minmax.low, number) // low angle
      function angle(a, h){
          return Math.acos(a/h)*180/Math.PI
      }
  
      if(la == 0 || ha == 0){
          nums = nums.slice(-30)
      }
  
  })
  
  num.get(&quot;walk&quot;, {rate: 50, base: 200, type: &quot;positive&quot;, scale: 2000, pseudo: false})
  </code></pre>
  <p>What I'm trying to figure out, is how to further find a min and max of the maximums (A); and then find a min and a max of the minimums (B).</p>
  <p>Please refer to this image for sections A and B in purple respectively:</p>
  <p><a href="https://i.stack.imgur.com/Z3maV.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Z3maV.jpg" alt="enter image description here" /></a></p>
  <p>I believe I need to set a new variable to the output of my <code>minMax</code> function but use smaller periods, but I'm not 100% sure. When I have tried this, I find that sometimes the max of the maximum range is also the max of the minimum range and the same is true for the min of the maximum and minimum ranges. Apologies if that's confusing. I hope the image makes it clear what I'm trying to accomplish.</p>
  <p>Any thoughts about how to solve this problem would be great!</p>