If one were inclined to approach this task in a more generic and functional manner, they might consider the following:
function allowIndices(idx) {
return function(item, index) {
return index % idx;
}
}
function calculateSum() {
return _.reduce(_.toArray(arguments)[0], function(result, current) {
return result + current;
}, 0);
}
var isIndexOdd = allowIndices(2);
var zippedData = _.zip(_.reject(data, isIndexOdd), _.filter(data, isIndexOdd));
console.log(_.map(zippedData, calculateSum));
# [ 3, 7, 11 ]
However, it should be noted that while this approach is certainly valid, it may not offer the same level of performance as the more traditional method shown below:
var results = [];
for (var i = 0; i < data.length; i += 2) {
results.push(data[i] + data[i + 1]);
}
console.log(results);