JavaScript — Comparing string letters. Freecodecamp Bonfire: Mutations Solution
Instructions:
Return true if the string in the first element of the array contains all of the letters of the string in the second element of the array.
For example, ["hello", "Hello"]
, should return true because all of the letters in the second string are present in the first, ignoring case.
The arguments ["hello", "hey"]
should return false because the string "hello" does not contain a "y".
Lastly, ["Alien", "line"]
, should return true because all of the letters in "line" are present in "Alien".
Here is a helpful link:
Step: 1
- Convert all letters to lowercase, as it will be easier to compare.
Step: 2
- Convert strings into arrays of characters, so that we can use a loop to iterate through the arrays.
Step: 3
- Setting up our loop: Use
indexOf()
to check if the letter of the second word is on the first.