Tell us what’s happening:
I am trying to : 1) using regex, split into arrays the words to be compared, so each regex would allow to set an array. 2) Compare an element of one array with another one from the other array. 3) if it works, I would implement regex working with any input and proceed to iterate to solve the challenge.
I am stuck in the second step: I couldn’t get the if else
statement working out…
Your code so far
const myArray = ['hello', 'hey'];
let strFromMyArray = myArray.join(", ").toLocaleLowerCase();
let myRegex = /hello/;
let arrFromFirstWord = strFromMyArray.match(myRegex);
let myRegex2 = /hi/;
let arrFromSecondWord = strFromMyArray.match(myRegex2);
function comparing (arr1, arr2) {
if (arr1[0] == arr2[0]) { //I'm intending to compare without a loop,
return true; //just to see if it works
} else {
return false;
}
}
console.log(comparing(arrFromFirstWord, arrFromSecondWord));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36 OPR/63.0.3368.94
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/mutations/