- Joined
- May 22, 2018
- Messages
- 3,261
- Reaction score
- 2,537
- First Language
- Portuguese - Br
- Primarily Uses
- RMMZ
Hi people!
Well, after I see a lot of things on the internet, I can't figure that out.
I see some examples with .some() and with .every() but I can't manage to put it in my code and it works.
In the code below, the variables a,b,c will get a random value between 0 and 3.
So, if any of them are equal( a = b || a = c || b= c), then the code will make a random value again for each one of the variables. If not, the loop will break and the code will proceed.
my code:
How can I check if are any equal values inside an array?
I manage to do that. But only when I specify the arrays.
But, in case that will be a lot of arrays. How can I make it simple? Like putting in the "if(any arrays are equal == false)" { then i execute my code}
Thanks!
Well, after I see a lot of things on the internet, I can't figure that out.
I see some examples with .some() and with .every() but I can't manage to put it in my code and it works.
In the code below, the variables a,b,c will get a random value between 0 and 3.
So, if any of them are equal( a = b || a = c || b= c), then the code will make a random value again for each one of the variables. If not, the loop will break and the code will proceed.
my code:
Code:
var a, b, c, habitat;
function SetHabitat() {
a = Math.floor(Math.random()*4);
b = Math.floor(Math.random()*4);
c = Math.floor(Math.random()*4);
return;
};
for (var habitat = [a, b, c];; SetHabitat()) {
if((a !== b) && (a !== c) && (c !== b)) {
habitat = [a, b, c];
break;
}
};
console.log(habitat);
How can I check if are any equal values inside an array?
I manage to do that. But only when I specify the arrays.
But, in case that will be a lot of arrays. How can I make it simple? Like putting in the "if(any arrays are equal == false)" { then i execute my code}
Thanks!