Created
December 30, 2009 19:02
-
-
Save gabrielgilini/266289 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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