Saudações!
Seguindo os posts anteriores, criei uma função para checar se há ARRAY em ARRAY.
Segue a função:
function arrayInArray(hayArray, staArray)
{
var fixString = staArray.toString();
for(var key in hayArray) if((fixString.indexOf(hayArray[key])) != -1) {
return true;
}
return false;
};
É meio difícil de entender, mas vamos lá
Digamos que eu tenha array1 e array2:
ARRAY1
ELEMENTO 0 -> "A"
ELEMENTO 1 -> "B"
ELEMENTO 2 -> "C"
ARRAY 2
ELEMENTO 0 -> "D"
ELEMENTO 1 -> "O"
ELEMENTO 2 -> "A"
Ele irá retornar TRUE. Pois o elemento 0 e 2 tem os mesmos valores, entenderam? Ele compara valores dentro dela.
Assim podendo criar funções legais. Do tipo:
function haveLowerChar(str)
// Checar se tem caracter MINUSCULO na string
// Retorna true e false
{
return arrayInArray((str.split("")), ("abcdefghijklmnopqrstuvwxyz".split("")));
}
Viram? Simples, mas eficiente.
Espero que gostem. Abraços