...

View Full Version : array problem



fvnnmike
04-13-2005, 03:57 AM
hi there,
i got this 20 numbers to be printed in javascript.
the problem is we are not allowed to print out the number that already been read before.
please help, every single help would be appreciated :)

WMJB
04-13-2005, 07:55 AM
here you go



var aFirst = new Array(1,2,3,2,4,3,4,5,6,7,5,6,7,8,9,45,21,11,4,5);
var aSecond = new Array();

for(i=0; i<aFirst.length;i++)
{
if(checkSecond(i)) document.write(aFirst[i] + ", ")
}
function checkSecond(i)
{
for(y=0; y<aSecond.length; y++)
{
if(aFirst[i]==aSecond[y]) return 0;
}
aSecond[aSecond.length] = aFirst[i];
return 1;
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum