title: nodejs refactor if condition function
body: <p>I have this function </p>
  
  <pre><code>//===========[Ranks depeonds on the totalPoints]================
  // Ranks Discribution: 1 = Bronze / 2 = Silver / 3 = Gold / 4 = Platinum / 5 = Diamond / 6 = Master / 7 = Challenger
  // If was used instead of switch for performance improvment
  const rank = (totalPoints, pointsRank) =&gt; {
      if (totalPoints &gt;= pointsRank[0] &amp;&amp; totalPoints &lt; pointsRank[1]) {
          return ({
              rank: 1,
              pointsLeftForNextRank: (pointsRank[1] - totalPoints)
          })
      } else if (totalPoints &gt;= pointsRank[1] &amp;&amp; totalPoints &lt; pointsRank[2]) {
          return ({
              rank: 2,
              pointsLeftForNextRank: (pointsRank[2] - totalPoints)
          })
      } else if (totalPoints &gt;= pointsRank[2] &amp;&amp; totalPoints &lt; pointsRank[3]) {
          return ({
              rank: 3,
              pointsLeftForNextRank: (pointsRank[3] - totalPoints)
          })
      } else if (totalPoints &gt;= pointsRank[3] &amp;&amp; totalPoints &lt; pointsRank[4]) {
          return ({
              rank: 4,
              pointsLeftForNextRank: (pointsRank[4] - totalPoints)
          })
      } else if (totalPoints &gt;= pointsRank[4] &amp;&amp; totalPoints &lt; pointsRank[5]) {
          return ({
              rank: 5,
              pointsLeftForNextRank: (pointsRank[5] - totalPoints)
          })
      } else if (totalPoints &gt;= pointsRank[5] &amp;&amp; totalPoints &lt; pointsRank[6]) {
          return ({
              rank: 6,
              pointsLeftForNextRank: (pointsRank[6] - totalPoints)
          })
      } else if (totalPoints &gt;= pointsRank[6]) {
          return ({
              rank: 7,
              pointsLeftForNextRank: 0
          })
      } else {
          return ({
              rank: 0,
              pointsLeftForNextRank: (pointsRank[0] - totalPoints)
          })
      }
  }
  module.exports = rank
  </code></pre>
  
  <p>and I call it like this</p>
  
  <pre><code>            let pointsRank = [150, 500, 1000, 2000, 3500, 5000, 5500]
              let totalPoints = 1200
              rank(totalPoints, pointsRank)
  </code></pre>
  
  <p>output</p>
  
  <pre><code>{ rank: 3, pointsLeftForNextRank: 600 }
  </code></pre>
  
  <p>how can I improve this function? I feel like that I wrote a lot of code which can be refactored into something smaller<br>
  like a small amount of code that does the same functionality
  also, I need to know if am violating any of the SOLID principles </p>