View difference between Paste ID: CCnRxGWk and QiWz2n0C
SHOW: | | - or go back to the newest paste.
1
  String.prototype.trim = function() {
2
  var str = this,
3
  whitespace = ' \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000';
4
  for (var i = 0,len = str.length; i < len; i++) {
5
    if (whitespace.indexOf(str.charAt(i)) === -1) {
6
      str = str.substring(i);
7
      break;
8
    }
9
  }
10
  for (i = str.length - 1; i >= 0; i--) {
11
    if (whitespace.indexOf(str.charAt(i)) === -1) {
12
      str = str.substring(0, i + 1);
13
      break;
14
    }
15
  }
16
  return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
17
}