I passed this challenge but the first solution I came up didn’t work. And I can’t understand why it’s not working even all results fit with expectations. Is there anyone to explain me why?
The code who gives expected output but doesn’t pass. 
function titleCase(str) {
var total=[];
str = str.toLowerCase().split(" ");
for(i =0; i<str.length; i++){
total += str[i][0].toUpperCase() + str[i].slice(1).toLowerCase() + " ";
}
return total;
}
titleCase("I'm a little tea pot");
The code I passed the challenge 
function titleCase(str) {
var arr = str.split(" ");
var newArr = arr.map(function(val){
var x = val[0].toUpperCase() + val.slice(1).toLowerCase();
return x;
});
return newArr.join(" ");
}
titleCase("I'm a little tea pot");
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36.
Link to the challenge:
https://www.freecodecamp.org/challenges/title-case-a-sentence