Looking for feedback: Basic Algorithm Scripting - Mutations

Hello all,

I have completed the challenge and passed all the tests using regex but I’m unclear on my solution as it seems messy. I’m not sure if this is the right place to look for feedback(or if that is a thing at all) so please remove if that’s the case.

Basically I’m looking for someone experienced to tell me if my solution is bad and why or why not :slight_smile:


function mutation(arr) {
for(let i = 0; i < arr[1].length; i++){
  var myReg = new RegExp(arr[1][i], 'i')
  var checkLetter = myReg.test(arr[0])
  if(!checkLetter){
    return false
  }
}
return true
}

mutation(["hello", "Hello"]);
  **Your browser information:**

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

Challenge: Mutations

Link to the challenge:

It looks great, I don’t see any actual issues. I personally find it quite clear and not messy. If I were to actually nitpick I would:

  1. have proper indentation (though I’m not sure if this is due to copy/paste issue)
  2. use let/const instead of var (not sure if you learned that at this point)
  3. use String.prototype.indexOf() instead of regExp as usually that would be faster for plain string matching. (but this makes such a minimal difference I feel odd even pointing it out)

I can see that you have great use of whitespace, descriptive variable names, clear and easy to follow code. This is really good work. Good job!

Thanks a lot for the reply, much appreciated!

use String.prototype.indexOf() instead of regExp as usually that would be faster for plain string matching.

This is what I was looking for, I will try it with .indexOf() as well, especially if it’s a more common practice. Thanks again.

1 Like

If you just want a true or false value then includes is also an option.

If you do not need the index includes feels more appropriate than indexOf in my opinion (sort of like test vs match with regex).

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.