4
Talk people, all good?
My doubt is simple, but the solution may not be so simple.
The truth is that I am doing a job in JS and soon I will need to solve a problem that will make me spend a few hours cracking my head.
So I decided to ask here at Stackoverflow to advance a little of the solution.
Let’s go to problematic.
Suppose I have declared 5 arrays, follow:
var objetos = ["abridor de garrafa", "abridor de latas", "adaga", "ábaco", "abajur", "abotoadura", "acetona", "açucareiro", "zabumba", "xícara", "zarabatana", "xilofone"];
var redondos = ["ábaco", "abajur", "abotoadura", "acetona", "açucareiro", "zabumba", "xícara"];
var cozinha = ["abridor de garrafa", "abridor de latas", "açucareiro", "xícara"];
var arma = ["adaga", "zarabatana"];
var musical = ["xilofone", "zabumba"]
Now, I need a function that when I pass 2 (or more) arrays, it returns me a new array, containing only the strings that are present in ALL arrays that I have passed.
Exemplifying:
If I pass to the function the arrays: "objects", "round" and "musical", the new array I receive, should contain only "zabumba".
Strange that it makes it seem like you want us to do your job so you don’t have to do it when it’s necessary. The solution is pretty simple too, so I’ll wait for you to first try to do it to only then help you.
– Woss
@Andersoncarloswoss I understand your vision, but it’s just that this is a very small part of something bigger that I’m doing and that I know it’s going to take a little while to find the most optimized solution, this inclusive, is another point that makes me come here to ask the staff and see the solutions and discuss, until arriving at a more optimized.
– FabianoLothor
I also understand you and, particularly, these are the discussions that I like most here, but without you trying to do something that would just be us arguing and you hoping for the best solution, right? And from personal experience, this time that you think it will take to arrive at a solution will be exactly the time that will make you understand the solution. Tip for when to try: think simple and do the simple.
– Woss