Help with Basic Algorithm Scripting: Mutations

Hi guys,

I don’t understand why my code doesn’t work for the first case but works with all the others…
Thanks in advance for you help

Your code so far

function mutation(arr) {

let firstElementArr = arr[0].split('')
let secondPart= arr.slice(1, firstElementArr.length).join('').toLowerCase()
let secondPartArr = secondPart.split('');

for (let i=0 ; i<=secondPartArr.length ; i++){
  return true
return false

console.log(mutation(["hello", "hey"]));

Your browser information:

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

Challenge: Mutations

Link to the challenge:

you are just checking the first character, for the other cases checking the first character will accidentally give the right result but not in this case.

The above is the inside of your loop, as one of the return statements will always execute, your loop stops at index 0 because a return statement stops the function and returns a value

1 Like