lundi 21 septembre 2015

if else in for loop over array javascript

I'm sure this is simple, but can someone please tell me why my code won't run the if statement in this for loop? I'm trying to solve this and would appreciate a hint on where i'm going wrong rather than the answer. I'm trying to find the appropriate element index where num would fit in a sorted array so in this case the function should return 3.

function where(arr, num) {
    // Find my place in this sorted array.
    arr.sort();
    for (var i = 0; i > arr.length; i++) {
       if(arr[i]<num){
         return arr[i]
       }
    }
}

where([10, 20, 30, 40, 50], 35);

Aucun commentaire:

Enregistrer un commentaire