Javascript refactor if condition function I have this function 

    const rank = (totalPoints, pointsRank) =&gt; {
    if (totalPoints &lt;= pointsRank[0]) {
        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
        })
    }
}
module.exports = rank


and I call it like this

            let pointsRank = [150, 500, 1000, 2000, 3500, 5000, 5500]
            let totalPoints = 1200
            rank(totalPoints, pointsRank)


output

{ rank: 3, pointsLeftForNextRank: 600 }


how can I improve this function? I feel like that I wrote a lot of code which can be refactored into something smaller
like a small amount of code that does the same functionality
also, I need to know if am violating any of the SOLID principles
Basically we search for the most close number from array where our number belongs. After we find the min value, we take the index of it and add 1, because the rank starts from 1



//rank 1 : 150 - 500
//rank 2 : 500 - 1000
//rank 3 : 1000 - 2000
//rank 4 : 2000 - 3500
//rank 5 : 3500 - 5000
//rank 6 : 5000 - 5500

let pointsRank = [150, 500, 1000, 2000, 3500, 5000, 5500]

function rank(pointsRank, score) {
  var closest = pointsRank.reduce(function(prev, curr) {
    return (Math.abs(curr - score) &lt; Math.abs(prev - score) ? curr : prev);
  });
  var rank = pointsRank.indexOf(closest) + 1; // cuz starts from 0 and we don't have rank 0
  console.log("min range: " + closest +
    " | our score: " + score +
    " | max range: " + pointsRank[rank])

  return {
    rank: rank,
    pointsLeftForNextRank: (pointsRank[rank] - score)
  }

}

const test1 = rank(pointsRank, 1200);
const test2 = rank(pointsRank, 2000);
const test3 = rank(pointsRank, 3700);

console.log(test1);
console.log(test2);
console.log(test3);