-
-
Save quackingduck/b9ca98bad23194144a1d 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
var nestedListMatch = function(lists, match) { | |
var firstItem = lists[0]; | |
if(firstItem === match) { | |
return match; | |
}else if (Array.isArray(firstItem)){ | |
var result = nestedListMatch(firstItem, match) | |
if(result === match) { | |
return match; | |
} | |
} | |
var newList = lists.slice(1); | |
return (newList.length>0) ? nestedListMatch(newList, match) : null; | |
} | |
var nestedList = [[1,2,[3,4,5]], 6, 9]; | |
console.log(nestedListMatch(nestedList, 2)) | |
console.log(nestedListMatch(nestedList, 5)) | |
console.log(nestedListMatch(nestedList, 9)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment