Mutations (using regex to finish this, only way I know how :| it's okay now, I managed to solve it)

Mutations (using regex to finish this, only way I know how :| it's okay now, I managed to solve it)
0

#1

Tell us what’s happening:
Hello, so I can’t finish this due to this
mutation(["hello", "neo"]) should return false.

mutation(["voodoo", "no"]) should return false.
these two are the last that for some reason I just can’t get and I don’t understand why it’s not working. Though I don’t really get how my code works xD

this might help
instead of neo:
n //false;
ne //true;
neo // true;
neow // false;

what’s up? O.O

I figured it out if anyone’s interested

function mutation(arr) {
let arrCompare = arr.pop();
let arrMain = arr.pop();
let arrComp = arrCompare.split("");
let result;
for (let i = 0; i < arrComp.length; i++){
let regex = arrComp[i];
let newRegex = new RegExp(regex, “ig”);
result = newRegex.test(arrMain);
if (result == false) {
return false;
}
}
return result;
}

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

Your code so far


function mutation(arr) {
 
 let arrCompare = arr.pop();
 let arrMain = arr.pop();
let arrComp = arrCompare.split("");
let result;

for (let i = 0; i < arrComp.length; i++){
let regex = arrComp[i];
console.log(regex);
let newRegex = new RegExp(regex, "ig");
result = newRegex.test(arrMain);
} if (result === true) {
  return true;
} else {
  return false;
}
}
mutation(["hello", "neo"]);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/mutations


#2

if anyone’s interested, I managed to solve it using regex, now I’m dreading to see the FCC solution which I am guessing is mindblowingly more elegant but this is the only way I could see how to do it 8D

function mutation(arr) {
let arrCompare = arr.pop();
let arrMain = arr.pop();
let arrComp = arrCompare.split("");
let result;
for (let i = 0; i < arrComp.length; i++){
let regex = arrComp[i];
let newRegex = new RegExp(regex, “ig”);
result = newRegex.test(arrMain);
if (result == false) {
return false;
}
}
return result;
}

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