Permalink
Browse files

better titleize, only 1 loc and up to 3x times faster

  • Loading branch information...
rwz committed Mar 1, 2012
1 parent 54a8904 commit 81d2cf25744f58840fa58bffef1cdc90d14008cf
Showing with 3 additions and 8 deletions.
  1. +2 −0 Gemfile.lock
  2. +1 −8 lib/underscore.string.js
View
@@ -11,6 +11,7 @@ GEM
rack (1.4.1)
rack-test (0.6.1)
rack (>= 1.0)
+ rake (0.9.2.2)
serve (1.5.1)
activesupport (~> 3.0)
i18n
@@ -28,5 +29,6 @@ PLATFORMS
ruby
DEPENDENCIES
+ rake
serve
uglifier
View
@@ -266,14 +266,7 @@
},
titleize: function(str){
- var arr = (''+str).split(' '),
- word;
- for (var i=0; i < arr.length; i++) {
- word = arr[i].split('');
- if(typeof word[0] !== 'undefined') word[0] = word[0].toUpperCase();
- i+1 === arr.length ? arr[i] = word.join('') : arr[i] = word.join('') + ' ';
- }
- return arr.join('');
+ return (''+str).replace(/\b./g, function(ch){ return ch.toUpperCase(); })
},
camelize: function(str){

0 comments on commit 81d2cf2

Please sign in to comment.