Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function titleCase(str) {
- //split sentence into array
- //find first letter of each string
- //change letter to caps
- //change array back into string
- var arr = str.split(' ');
- var newArr = []
- arr.map(function(item) {
- //item.replace(/^./, item[0].toUpperCase);
- newArr.push(item.toLowerCase().replace(/^./, item[0].toUpperCase()));
- });
- return newArr.join(' ');
- }
- titleCase("I'm a liTtle tea pot");
Add Comment
Please, Sign In to add comment