Mutaciones en javascript

Hola respetados developers, estoy tratando de resolver un ejercicio de javascript, Mutaciones, pero no he podido verificar si las letras de un string están en el primer string del array, el ejercicio dice:

Devuelve true si la cadena de caracteres en el primer elemento del arreglo contiene todas las letras de la cadena en el segundo elemento del arreglo.

Por ejemplo, ["hello", "Hello"], debe devolver true porque todas las letras de la segunda cadena están presentes en la primera, ignorando mayúsculas o minúsculas.

Los argumentos ["hello", "hey"] deben devolver false porque la cadena hello no contiene y.

Finalmente, ["Alien", "line"], debe devolver true porque todas las letras de line están presentes en Alien.

Mi código hasta el momento pasó ciertas pruebas, menos tres. Dejo mi código aquí:

function mutation(arr) {
let arr1 = arr[0].toLowerCase().split(“”).sort().toString(“”);
let arr2 = arr[1].toLowerCase().split(“”).sort().toString(“”);
if(arr1.includes(arr2)){
return true;
}else{
return false;
}
}

mutation([“hello”, “hey”]);

Qué no estoy viendo o contemplando dentro de mi código ?

This is not going to produce the correct results a lot of the time. If the first string is “abcde” and the second string is “ace” then the function should return true because all of the letters in the second string are in the first string. But your function returns false. Do you know what the values of arr1 and arr2 are when this statement runs. You might want to console.log them before the if statement and hopefully you’ll see why your function is not working. You’ll need to come up with another way for determining if all of the letters in the second string are in the first.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.