gharizanov92
9/30/2014 - 1:33 PM

BeerAndFries.js

exports.beerAndFries = function(items){

    var beers = [];
    var fries = [];

    for(var i in items){
        var item = items[i];
        if(item.type == 'beer'){
            beers.push(item.score);
        } else {
            fries.push(item.score);
        }
    }

    beers.sort(function(a, b){return a<b});
    fries.sort(function(a, b){return a<b});

    var max = 0;
    for(var beer in beers){
        max += beers[beer]*fries[beer];
    }
    return max;
};