Deriving stars from a product score This function derives a 'stars' rating from a product score that is retrieved from local storage.  What would be the best way to refactor these else if statements?

    $scope.ratingStars = function(productID) {

        var bottomLine = $filter('filter')($localStorage.bottomlinesObject.bottomlines, {domain_key:''+productID})//jshint ignore:line

        if(bottomLine.length &gt; 0) {

            if (bottomLine[0].product_score === 'undefined') {return 0;}//jshint ignore:line
            else if(bottomLine[0].product_score &gt; 0 &amp;&amp; bottomLine[0].product_score &lt;=1.5)  {return 1;}// jshint ignore:line
            else if(bottomLine[0].product_score &gt; 1.5 &amp;&amp; bottomLine[0].product_score &lt;=2) {return 2;}//jshint ignore:line
            else if(bottomLine[0].product_score &gt; 2 &amp;&amp; bottomLine[0].product_score &lt;=2.5) {return 2.5;}//jshint ignore:line
            else if(bottomLine[0].product_score &gt; 2.5 &amp;&amp; bottomLine[0].product_score &lt;=3.2) {return 3;}//jshint ignore:line
            else if(bottomLine[0].product_score &gt; 3.2 &amp;&amp; bottomLine[0].product_score &lt;=3.7) {return 3.5;}//jshint ignore:line
            else if(bottomLine[0].product_score &gt; 3.7 &amp;&amp; bottomLine[0].product_score &lt; 4.3) {return 4;}//jshint ignore:line
            else if(bottomLine[0].product_score &gt;= 4.3 &amp;&amp; bottomLine[0].product_score &lt; 4.75) {return 4.5;}//jshint ignore:line
            else if(bottomLine[0].product_score &gt;= 4.75 &amp;&amp; bottomLine[0].product_score &lt; 5) {return 5;}//jshint ignore:line
            else if(bottomLine[0].product_score &gt;= 5) {return 5;}// jshint ignore:line

        }


        else {return 0;}


    };
Since the intervals aren't consistent, rounding wouldn't help, but you can drop the floor condition since you're using else-if.

    if(bottomLine.length &gt; 0) {
        if (bottomLine[0].product_score === 'undefined') {return 0;}//jshint ignore:line
        else if(bottomLine[0].product_score &lt;=1.5)  {return 1;}// jshint ignore:line
        else if(bottomLine[0].product_score &lt;=2) {return 2;}//jshint ignore:line
        else if(bottomLine[0].product_score &lt;=2.5) {return 2.5;}//jshint ignore:line
        else if(bottomLine[0].product_score &lt;=3.2) {return 3;}//jshint ignore:line
        else if(bottomLine[0].product_score &lt;=3.7) {return 3.5;}//jshint ignore:line
        else if(bottomLine[0].product_score &lt; 4.3) {return 4;}//jshint ignore:line
        else if(bottomLine[0].product_score &lt; 4.75) {return 4.5;}//jshint ignore:line
        else {return 5;}//jshint ignore:line
    }


And, since you're returning each time, you can drop the "else" part of the else if for that matter.

    if(bottomLine.length &gt; 0) {
        if (bottomLine[0].product_score === 'undefined') {return 0;}//jshint ignore:line
        if(bottomLine[0].product_score &lt;=1.5)  {return 1;}// jshint ignore:line
        if(bottomLine[0].product_score &lt;=2) {return 2;}//jshint ignore:line
        if(bottomLine[0].product_score &lt;=2.5) {return 2.5;}//jshint ignore:line
        if(bottomLine[0].product_score &lt;=3.2) {return 3;}//jshint ignore:line
        if(bottomLine[0].product_score &lt;=3.7) {return 3.5;}//jshint ignore:line
        if(bottomLine[0].product_score &lt; 4.3) {return 4;}//jshint ignore:line
        if(bottomLine[0].product_score &lt; 4.75) {return 4.5;}//jshint ignore:line
        return 5; //jshint ignore:line
    }


I think you should remove the redundant floor conditions, but I can see a case made either way with leaving the "else" in place.