In it’s current state my code only returns true and with some rearranging it stays the same or changes to false. I thought using the .split()
method would fix the problem but I still need some help. Here’s the code.
function mutation(arr) {
var str = arr.join();
arr = str.toLowerCase();
arr = str.split("");
if (arr[0] != arr[1]) {
return true;
} else {
return false;
}
}
mutation(["hello", "hey"]);
function mutation(arr)
["hello", "hey"]
var str = arr.join();
"hello,hey"
arr = str.toLowerCase();
"hello,hey"
arr = str.split("");
["h","e","l","l","o",",","h","e","y"]
if (arr[0] != arr[1]) {
if("h" != "e")
Your code doesn’t seem to work when I type it in.
That is a description of what is occurring in your code. If you look, that is, line by line, your code followed by what the state is. You end up checking if the first letter is equal to the second letter in the first word.
By joining the array you’ve been given, you immediately lose the ability to differentiate properly; you’ve just created a single string. If you split it back up the way you’ve done, you just get one array of all the characters. You already have the two different strings: compare those, don’t join them together.
Thanks for the help. I finally got it.