for vs search

Edit on GitHub

Setup

var foo = 'um texto bem grande         ';

Tests

  • for

    var c = 0;
    for (var i = foo.length - 1; i > 0; i--) {
      if (foo[i] == ' ') c++; else break;
    }
  • search

    foo.search(/\s$/)