Grade student as number of array scores Assume that you have the ready sorted array

Is it a good solution?

Plunker OR:

&lt;script&gt;
    var score = [10, 20, 20, 20, 40, 50, 60, 60, 60, 60, 70, 80, 80, 90]
    var j = 0;
    var k = 0;

    for( i in  score ){
        var grade = '';

        if( i== 0 || score[i] &gt; score[i - 1] ){
            grade = j = j+1+k;
            k = 0;
        }else{
            k++;
            grade = j;
        }

        document.write( 'Grade: ' + ( grade ) +'&lt;br&gt;');
    }
    &lt;/script&gt;
The value your looking for is more like a position rather then a grade. 
Just add...

var position   = 0; 
var last_grade = 0; 


outside the for loop. then add a comparison before the document.write... statement like so.

if (grade&gt;last_grade) position++;
document.write( 'Grade: ' + ( position ) +'&lt;br&gt;');
last_grade=grade;


That should give you the following result...

Grade: 1&lt;br&gt;
Grade: 2&lt;br&gt;
Grade: 2&lt;br&gt;
Grade: 2&lt;br&gt;
Grade: 3&lt;br&gt;
Grade: 4&lt;br&gt;
Grade: 5&lt;br&gt;
Grade: 5&lt;br&gt;
Grade: 5&lt;br&gt;
Grade: 5&lt;br&gt;
Grade: 6&lt;br&gt;
Grade: 7&lt;br&gt;
Grade: 7&lt;br&gt;
Grade: 8&lt;br&gt;