Created
July 14, 2014 04:08
-
-
Save wmeredith/08a29e9ba9cae5d86483 to your computer and use it in GitHub Desktop.
Recursively Combine Arrays in jquery
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
recursiveSearch = function (text, depth ) { | |
var a = [ ['1','2','3'], ['a','b','c'] ]; | |
var results = [""]; // start with the empty string, | |
for (var i=0; i<a.length; i++) { // and repeatedly | |
var ai = a[i], | |
l = ai.length; | |
results = $.map(results, function(r) { // make result a new array of | |
var ns = []; // new combinations of | |
for (var j=0; j<l; j++) // each of the letters in ai | |
ns[j] = r + ai[j]; // and the old results | |
return ns; | |
}); // using the odds of jQuery.map with returned arrays | |
} | |
return results; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment