arr contains two strings, so arr[0]
is for the first string
and arr[1]
is for the second string
.
What you do actually is the following:
you take the second string
(i.e. arr[1]) you change to lowercase, then you split it (you will have an array), and you use the method every
, to check if every element of the array satisfies the function (the function return true
or false
), if yes, the mutation function will return true else it will return false.
what the function
inside the every
method does is simply, checks if the first string contains the letter
, (the letter is a variable that changes because The every method executes the provided callback function once for each element present in the array).
How does the function check? it take the first string , turns it to lowercase (because uppercase is not the same as lowercase), and then checks the index of letter
inside the first string using the method indexOf
(you can use indexOf on strings), the indexOf method return “-1” if the element is not found, so it is like writing the function like that
function(letter) {
return (index of letter inside the first string) != -1;
// if (index of letter inside the first string) is not found (i.e -1), the expression becomes -1 != -1 which is false, then there is a letter missing, which means " the string in the first element of the array DOES NOT contain all of the letters of the string in the second element of the array"
}
TL;DR: the function simply checks if letter
is present in the first string.