Ternary operator isn’t necessary in this case since it always return true or false, for example you can do :
function isEquals4(num) {
return num == 4;
}
That’s what @codefu-chivy said.
Ternary operator isn’t necessary in this case since it always return true or false, for example you can do :
function isEquals4(num) {
return num == 4;
}
That’s what @codefu-chivy said.
Was just providing an alternative
var first = arr[0].toLowerCase();
var second = arr[1].toLowerCase();
var c = "false";
for ( var i = 0; i < second[1].length; i++ ) {
c = first.indexOf(second[i],0) !== -1;
if ( c == false ) {
break;
}else{
c = true;
}
}
return c;
}
mutation(["hello", "hey"]);```
I seem to have a serious misunderstanding of this problem, still get all but one test to pass. Also, the backtick thing doesn’t seem to work…
The triple backticks should be in their own lines. Like:
``` code goes here ```
function mutation(arr) {
var first = arr[0].toLowerCase();
var second = arr[1].toLowerCase();
var c = "false";
for ( var i = 0; i < second[1].length; i++ ) {
c = first.indexOf(second[i],0) !== -1;
if ( c == false ) {
break;
}else{
c = true;
}
}
return c;
}
mutation(["hello", "hey"]);
Hi
var c = "false";
you probably mean
var c = false;
for ( var i = 0; i < second[1].length; i++ ) {
you probably mean
for ( var i = 0; i < second.length; i++ ) {
You want to loop over the characters in the first string and for each one, you want to check it against every character in the second string - is that right? In that case, you will probably need two loops. Hope that helps a bit.
I didn’t catch the “false” mistake, thank you. Once i posted the code, I saw the [1] mistake, after removing it, the tests all passed. Yea, I have to make sure all the letters in “second” are present in “first” and return true or false.