"Title Case a Sentence" challenge. Watch out! Spoiler!

"Title Case a Sentence" challenge. Watch out! Spoiler!
0

#1

Well I did it. Here’s my code. But something is telling me it could be simpler what means better for me. Any ideas?

function titleCase(str) {
  var arr=str.toLowerCase().split(' ');
  var bigArr = [];
  for (i=0;i<arr.length;i++) {
    bigArr.push(arr[i].split(""));
  }
  for(i=0;i<bigArr.length;i++) {
    bigArr[i][0]=bigArr[i][0].toUpperCase();
  }
  for (i=0;i<bigArr.length;i++) {
    arr[i]=bigArr[i].join('');
  }
  return arr.join(" ");
}

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

#2

You can use string[0] construction with gives you access to first char in string, and reduce number of for loops.


#3

Ah! This looks better I think.

function titleCase(str) {
  var arr=str.toLowerCase().split(' ');
  var tmpArr = [];
  for (i=0;i<arr.length;i++) {
    tmpArr = arr[i].split('');
    tmpArr[0] = tmpArr[0].toUpperCase();
    arr[i] = tmpArr.join('');
  }
  return arr.join(' ');
}

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