Skip to content

Instantly share code, notes, and snippets.

@wmeredith
Created July 14, 2014 04:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wmeredith/08a29e9ba9cae5d86483 to your computer and use it in GitHub Desktop.
Save wmeredith/08a29e9ba9cae5d86483 to your computer and use it in GitHub Desktop.
Recursively Combine Arrays in jquery
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