Camp | Phone | Change letters
Anonymous User
127

Hello, I am struggling with one challenge, I have to create a function that receives 2 strings and returns the number of moves needed, if there's no possibilities it has to return -1, I know that in the last part I am doing something wrong and I can't find the way to solve it better, this is my code:


let Emilie = "coffe"
let Mark`` = "eecoff"

function firstFunction(first, second) {
  let counter = 0;
  let arr = Array.from(first)
  let arr2 = Array.from(second)
  console.log(arr, arr2)
  
 for (i = 0; i < arr.length; i++) {
   counter++;
   arr.unshift(arr.pop());
   if (arr.toString() === arr2.toString()){
     console.log(counter)
     break;
   }
   return -1
 }      
}

firstFunction(Emile, Mark); 


Could anyone help me with this? I want to learn how to do a better aproach and be better in this kind of test.

Comments (1)