Hey guys,
my question is Hello and hello returns true for me.
but for example the elements in the code, not returning true.
Do I have to sort those letters out? that is my question.
You have to check for every single letter - as the order doesn’t matter. It only matters, that all letters are present. .includes() however checks if the exact order is present, hence it won’t work here.
Let’s go through the steps of that example above mutation(["Alien", "line"]) and plop in all the variables:
const loweredString = "Alien".toLowerCase(); // "alien"
const anotherLoweredString = "line".toLowerCase(); // "line"
for (let i = 0; i < "alien".length; i++) {
if ("line".indexOf("a") !== -1) { // this is false so let's tick up `i`
if ("line".indexOf("l") !== -1) { // this is true
return true; // bye!
Do you see how that’s kinda weird? It returns true after finding only one matching letter.
Nah, don’t overthink it, you are pretty close already.
Think about how you’d do it by hand: you have to check every letter of the second string. When is the earliest point you can say they are “all” contained? When is the earliest point you can say they are “not all” contained?