Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: array problem

  1. #1
    New to the CF scene
    Join Date
    Apr 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    array problem

    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

  • #2
    New Coder
    Join Date
    Mar 2005
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts
    here you go

    Code:
    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;
    }
    "It doesn't matter if I'm optomistic or not, nothing ever works out for me."


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •