Search and Replace code showing wrong

Search and Replace code showing wrong
0

#1

Tell us what’s happening:

The bellow code is showing wrong but the console is showing the correct result please help.

Your code so far

function myReplace(str, before, after) {
  var tst = [];
  var str_arr = str.split(" ");
  for (var i = 0; i < str_arr.length; i++){
    
    if (str_arr[i] == before)
      str_arr.splice(i,1,after);
  }
  //return str_arr[1];
  return str_arr.join(' ');
}

myReplace("Let us get back to more Coding", "Coding", "algorithms");

Your browser information:

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

Link to the challenge:


#2

What do the failing tests say?


#3

On console the result is totally correct but few arguments are showing wrong in the result board.
I tried to match the length, and they matched.


#4

Which tests are failing?


#5


#6

Am I missing something?


#7

ohhhh! I see now…
thanks for your time.


#8

:+1:t2: Good job finding it on your own.