string compare vs string methods

Edit on GitHub

string compare vs method calls

Setup

var strings = [
  'hello',
  'party',
  'good_time',
  'internet'
];

Tests

  • string compare

    var i = Math.round(Math.random() * strings.length);
    
    strings[i] === 'good_time' ? 'good time' : strings[i];
  • string methods

    var i = Math.round(Math.random() * strings.length);
    
    strings[i].split('_').join(' ');