Basic Calculator Testing

by mrrodd

JavaScript

var a = function(x, y) {
    return x + y;
};
var s = function(x, y) {
    return x - y;
};

var operator = ['+', '-'],
    operation = [a, s];

var calc = function(x, y, op){
    var method = operation[operator.indexOf(op)];
    return method(x, y);
};



//console.log( add(14,5) );
//console.log( "Add:",calc(14, 5, a) );
//console.log( "Subtract:",calc(14, 5, s) );

//console.log( operation[operator.indexOf('+')] );

console.log( "Subtract:",calc(14, 5, '-') );