1

I'm working on a web scraper in and I need to produce a list of queries based on several arrays. This is already done in the request loop right now, but I want to do it ahead of time so I can blah blah blah and make maintaining this thing less painful.

So my problem is, for an arbitrary number of arrays, I need to get all of the possible combinations.

Let's start with this:

let array1 = ["lion","tiger","bear"];
let array2 = ["cat","dog","snake"];
let array3 = ["cockroach","spider","slug"];

I'd like something like: let queries[]; queries = magicfunction([array1,array2,array3])

I am trying to produce this output

[
   [ "lion", "cat", "cockroach"],
   [ "lion", "cat", "spider"],
   [ "lion", "cat", "slug"],
   [ "lion", "dog", "cockroach"], 
   [ "lion", "dog", "spider"],
   [ "lion", "dog", "slug"], 
   [ "lion", "snake", "cockroach"],
   [ "lion", "snake", "spider"],
   [ "lion", "snake", "slug"],
   [ "tiger", "cat", "cockroach"],
   [ "tiger", "cat", "spider"],
     ...
   [ "bear", "snake", "slug"]
]

And from there I can build up a google search query.

I know I will feel stupid when I see the answer, but I can't seem to fit this loop into my brain. Can someone help me out, please?

0 Answers0