Link to home
Start Free TrialLog in
Avatar of Isaac
IsaacFlag for United States of America

asked on

array in recurssive function

I'm trying to modify a function and use an array.  It's a private function that seems to be in a closure.
The problem I'm having is that when _GetDataTable makes a call to itself, the array resets (understandable).
When I declare the array outside of the function, I get duplicate values of the same data.  Any ideas how to fix?
Thanks!       

      
function _GetDataTable() //private function
	{ 
		var retVal = "";
		var chkVal = "";

		colHeader = new Array();
		dataTableData = new Array();
		
		//base case:
		if(arguments.length == 1)
		{
			var theCase;
			if( typeof arguments[0][0] == "string")
			{
				if(arguments[0][1] && __MatchCase(arguments[0][1])) 
				{
					
					if(arguments[0].length == 4)
					{	
						colHeader.push(arguments[0][2]);
						dataTableData.push(arguments[0][0]);
					}
					else if(arguments[0].length == 5) 
					{							
						colHeader.push(arguments[0][3]);
						dataTableData.push(arguments[0][0]);

					}
				}
			}
			else if((arguments[0].length == 4) || (arguments[0][2] && __MatchCase(arguments[0][2]))) 
			{
					colHeader.push(arguments[0][2]);
					dataTableData.push(arguments[0][0].getProperty(arguments[0][1]));	
			}
		}
		else
		{
			for(var i = 0; i < arguments.length; ++i)
			{
						retVal += _GetDataTable(arguments[i]);		
			}
		}	

		return retVal;
	};

Open in new window

Avatar of leakim971
leakim971
Flag of Guadeloupe image

declare outside (yes you get duplicate)
after it's done remove duplicate from the array(s)
Avatar of Isaac

ASKER

How would I remove the duplicates?
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial