Cod is not passin tests but can't find problem (Title Case a Sentence)

Tell us what’s happening:
When I try on my own the code seems to work just fine but it is not passing tests.
What am I missing? What is wrong?

Your code so far

function titleCase(str) {
  let s = [];
  str = str.split(' ');
  // Iterating through str and adding first letter of each word to s array and capitalize.
  for(let i = 0; i < str.length; i++){
    s += str[i][0].toUpperCase();

// Iterating through rest of str and adding other letters to s array and lowercase.

    for(let j = 1; j < str[i].length; j++){
      s += str[i][j].toLowerCase();

 // adding space beteween the words
    s += ' ';
  return s;

titleCase("I'm a little tea pot");

Your browser information:

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

Link to the challenge:

I think you are adding the space also at the end of the string, so you have an extra space that’s making the tests fail