Thread: Returning Index
View Single Post
Old Dec 10th, 2007, 3:07 AM   #2
hollystyles
Omlette du fromage
 
hollystyles's Avatar
 
Join Date: Oct 2007
Posts: 29
Rep Power: 0 hollystyles is on a distinguished road
Re: Returning Index

Just loop the array of integers in reverse.

var integerArray = [1,-2,0,4,-5,0,7,-8,0,10];
var positiveInts = [];
for(var i = integerArray.length - 1, i >= 0, --i)
{
     if(integerArray [i] >= 0)
        positiveInts[positiveInts.length] = integerArray[i];
}
hollystyles is offline   Reply With Quote