1

I have 3 datasets which are :

patterns=[
    "[foo] is a [bar]",
    "[foo] is not a [bar]",
    "[foo] could be a [bar]"
]

fooSet=[
    "a","b", "c"
]

barSet = [
    "d", "e", "f"
]

these data sets will be dynamic, it could be 5 different patterns and 4 data sets, I have already tried with lodash each and various loops but all I have got is soemthing like this:

"cat in {{country}} for {{cost}}"

"dog in {{country}} for {{cost}}"

"{{animal}} in mex for {{cost}}"

"{{animal}} in usa for {{cost}}"

"{{animal}} in {{country}} for cheap"

"{{animal}} in {{country}} for expensive"

with this data set:

{{animal}} in {{country}} for {{cost}}



cat
dog
iguana
bird

usa
mexico
denmark

cheap
expensive
good price

this is my code:

generateKeywords() {
     //first get an array of patterns
     var patternArray = this.patterns.split(',');
     _this = this;
     newArrayOfPatterns = [];
     _.each(this.elements, function(element) {
         _.each(patternArray, function(pattern) {
             subset = element.list_of_variations.split('\n');
             _.each(subset, function(val) {
                 result = pattern.replace(element.element_caught, val);
                 newArrayOfPatterns.push(result);
             })
         });
 })
}

where elements is an object conatining the words and patterns is the array of patterns

  • This question seems to encompass several different questions, and is unlikely to get an answer. I recommend you narrow down to one specific question, and consider reading the helpful article [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) – Hamms May 23 '18 at 01:33
  • If the specific question you care about is finding the "combinations", there are several duplicates already on SO. [this one even has a comment linking to several more](https://stackoverflow.com/questions/15298912/javascript-generating-combinations-from-n-arrays-with-m-elements?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa) – Hamms May 23 '18 at 01:36

0 Answers0