Last active
May 30, 2017 01:09
-
-
Save rodpoblete/0e0e20a46c5ca51806c8f4776929da95 to your computer and use it in GitHub Desktop.
Comprobar si palabra de un indice estaba en otro array - FCC[254]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mutation(arr) { | |
var arr1 = arr[0].toLowerCase().split(''); // seconvierten los strings a minusculas y se separan con split() | |
var arr2 = arr[1].toLowerCase().split(''); // primer array es la base, segundo array la palabra a buscar | |
for (var i = 0; i < arr2.length; i++) // ciclo for que reccorre el array | |
if (arr1.indexOf(arr2[i]) == -1) // compara si el indice del array uno con el del 2 son distintos -1 | |
return console.log('false'); // retorna false si no lo son | |
return console.log('true'); // true si lo son | |
} | |
mutation(["hello", "hey"]); // "false" porque la letra Y no esta en la palabra "hello" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment