Edit in JSFiddle

/**
 * Function that sums up values, based on the selector
 */
var totalSelectValues = function (values, selector) {
    //handle undefined selector
    if (typeof selector == 'undefined') {
        selector = function () { return true; };
    }

    var sum = 0;
    // sum up the values is selection is true
    values.forEach(function (value) {
        if (selector(value)) sum += value;
    });
    
    printAnswer(sum);
    return sum;
};

/**
 * Utility function for showing answer 
 */
var printAnswer = function (content) {
    var answer = document.getElementById("answer");
    answer.innerHTML += " || " + content;
};

// returns true if a number is even
var isEven = function(number) {
    return (number % 2 == 0);
};

var arrayOfValues = [1, 2, 3, 4, 5, 6, 7, 8, 9];

// sum all values
totalSelectValues(arrayOfValues);

// sum of even numbers
totalSelectValues(arrayOfValues, isEven);

// sum of odd numbers
totalSelectValues(arrayOfValues, function (e) {
    return (e % 2 !== 0);
});

// sum of all numbers > 5
totalSelectValues(arrayOfValues, function (e) {
    return (e > 5);
});
<span id="answer"></span>
<br/>
<br/>
<br/>
<br/>
<a href="http://tech.deepumohan.com/2013/07/javascript-pass-function-as-parameter.html">http://tech.deepumohan.com/2013/07/javascript-pass-function-as-parameter.html</a>