Search within two arrays

Asked

Viewed 74 times

0

the case is the following. I have a script that I wanted to use and as in all questions "I suppose" I do not know how to do. The following I want to do an array data search with javascript "pq do not suggest other languages if your answer is not in javascript please do not answer" inside another array like this:

i have the length array:

var comprimentos = new Array('OI', 'OLA', 'IAI', 'BLZ', 'TESTE', 'TUDO BEM', 'JOIA');

but to cover all options such as 'hi? ' which is different from 'hi' due to the interrogation I created a second array

var int = new Array('?', '!', '');

so I thought of something like this:

var comprimentos = new Array('OI'+int[y], 'OLA'+int[y], 'IAI'+int[y], 'BLZ'+int[y], 'TESTE'+int[y], 'TUDO BEM'+int[y], 'JOIA'+int[y]);

where var y is equivalent to a random number ranging from 0 to 2

but I have to confirm several times the code is giving too much error help me there

  • It got a little confusing. You want to check whether a given text contains any of the var length terms, but there may be variations of the second array, what interferes with the search for the items in the first array is this?

  • BASICALLY HE DID THE FOLLOWING:

  • WHEN I RESEARCHED HI HE GAVE THE PROGRAMMED ANSWER BUT PUT HI! NO LONGER GAVE. AND THE FINAL USER YOU KNOW HOW IT IS: UNPREDICTABLE! THEY WRITE THINGS LIKE IAI AND YOU KEEP THINKING HE’S GONNA WRITE HI

1 answer

4


To get all occurrences of the concatenation of the 2 arrays, just join them in this way...

var comprimentos = new Array('OI', 'OLA', 'IAI', 'BLZ', 'TESTE', 'TUDO BEM', 'JOIA');

var int = new Array('?', '!', ' ');

var ocorrencias = [];

comprimentos.forEach(function(c){
  ocorrencias.push(c);
  int.forEach(function(i){
    ocorrencias.push(c+i);
  });
});

console.log(ocorrencias);

  • IT WORKED LIKE A GLOVE FRIEND THANK YOU I WILL STUDY FURTHER THE CONCEPTS OF YOUR CODE BECAUSE I USED BUT I HAVE NO IDEA HOW IT WORKS YET BUT THANK YOU VERY MUCH

  • IF YOU COULD DO LIKE THE ANSWER BELIEVE ME, I WOULD

  • kkk, then yes, javascript is a hand on the wheel, the like purpose has to give the.o, here you can even choose the answer that helped you as best, in the upper left, below the votes

Browser other questions tagged

You are not signed in. Login or sign up in order to post.