One liner vs Two liner

Edit on GitHub

Tests a one line function against a two line function

Setup

var array= ['a', 'b', 'c', 'd', 'e'];
var size = array.length;

function twoLine(index) {
    index= ( (index % size) + size) % size;
        
    return array[index];
}

function oneLine(index) {
    return array[ ( (index % size) + size) % size ];
}

Tests

  • One liner

    for (var i= 0; i < 1000; i++) {
        oneLine(i);
    }
  • Two liner

    for (var i= 0; i < 1000; i++) {
        twoLine(i);
    }