Skip to content

Instantly share code, notes, and snippets.

@gabrielgilini
Created December 30, 2009 19:02
Show Gist options
  • Save gabrielgilini/266289 to your computer and use it in GitHub Desktop.
Save gabrielgilini/266289 to your computer and use it in GitHub Desktop.
function getPositionInMatrix(needle, haystack, pos)
{
pos = pos || [];
for(var i = haystack.length; --i >= 0;)
{
if(haystack[i] === needle)
{
return pos.push(i);
}
else if(Object.prototype.toString.call(haystack[i]) === '[object Array]')
{
pos.push(i);
if(getPositionInMatrix(needle, haystack[i], pos))
{
return pos;
}
else
{
pos.pop();
}
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment