2
I would like to perform the following in the variable img
right below: Get true if ALL images (tag img) are EQUAL, or false IF ONE OR MORE DIFFERENT of the others. I tried loop for
, but it does not work as expected, because I could not find a way to compare each index with the others and get a single true OR false. In the face of it, I had no idea what to do.
var img = '<img src="pic_1.jpg" />; <img src="pic_1.jpg" />; <img src="pic_1.jpg" />; <img src="pic_1.jpg" />'; // Todas as imagens são iguais - Daria true
var img = '<img src="pic_1.jpg" />; <img src="pic_2.jpg" />; <img src="pic_1.jpg" />; <img src="pic_1.jpg" />'; // Uma imagem é diferente das outras - Daria false
var img = '<img src="pic_1.jpg" />; <img src="pic_1.jpg" />; <img src="pic_2.jpg" />; <img src="pic_2.jpg" />'; // Duas imagens são diferentes das outras - Daria false
img = img.split(';');
for (var i = 0; i < img.length; i++) {
console.log(img[i] != img[0]);
}
agrees that instead of
qtdDiferentes++
you could make a directreturn true
and out of the going to make areturn false
? :)– Maicon Carraro
@Maiconcarraro this is much better, thank you.
– Sergio