hi ...
here is a recursion , suppose it will return a value and
but,,,when the function returned with a value ,and a var incept it,
still it is null or undefined..
the code here:
[CODE=javascript]function invokeRec () {
var v = dataQuery(data, query) ; //assume that data and query are available , i.e. data is an array with some elements and query is a valid term
alert(v); //
}
function dataQuery(data, query) {
if(typeof(data[query]) != "undefined" ) {
alert(data[query]) ; // here is valid and then return ...
return (data[query]);
}
for(var something in data) {
if ( typeof(data[something]) == "object"
&& typeof(data[something] != "undefined" )
&& something != query) {
dataQuery(data[something],query);
}
}
}[/CODE]
and here is the version2 :
[CODE=javascript]function dataQuery(data, query) {
for(var something in data) {
if ( typeof(data[something]) == "object"
&& typeof(data[something] != "undefined" )
&& something != query) {
dataQuery(data[something],query);
} else if (something == query) {
return (data[query]);
}
}
}
[/CODE]
what's the problem with these two snippets of code?
Thank you!
here is a recursion , suppose it will return a value and
but,,,when the function returned with a value ,and a var incept it,
still it is null or undefined..
the code here:
[CODE=javascript]function invokeRec () {
var v = dataQuery(data, query) ; //assume that data and query are available , i.e. data is an array with some elements and query is a valid term
alert(v); //
}
function dataQuery(data, query) {
if(typeof(data[query]) != "undefined" ) {
alert(data[query]) ; // here is valid and then return ...
return (data[query]);
}
for(var something in data) {
if ( typeof(data[something]) == "object"
&& typeof(data[something] != "undefined" )
&& something != query) {
dataQuery(data[something],query);
}
}
}[/CODE]
and here is the version2 :
[CODE=javascript]function dataQuery(data, query) {
for(var something in data) {
if ( typeof(data[something]) == "object"
&& typeof(data[something] != "undefined" )
&& something != query) {
dataQuery(data[something],query);
} else if (something == query) {
return (data[query]);
}
}
}
[/CODE]
what's the problem with these two snippets of code?
Thank you!
Comment