Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
"Treasures" solution in Clear category for [old] Treasures by capback250
'use strict';
function treasures(info, lim) {
let limit = lim * 1000;
const counter = {
'golden coin': 0,
'silver coin': 0,
'ruby': 0
};
Object
.keys(info)
.map(treasureType => {
const {price, weight, amount} = info[treasureType];
return {price, weight, amount, realValue: price / weight, treasureType};
})
.filter(el => el.weight <= limit)
.sort((a, b) => b.realValue - a.realValue)
.map(el => {
let {weight, amount, treasureType} = el;
while (amount) {
if (!limit) { return }
if (weight <= limit) {
limit -= weight;
amount -= 1;
counter[treasureType]++;
}
}
});
return Object
.keys(counter)
.filter(key => counter[key] > 0)
.map(el => `${el}: ${counter[el]}`);
}
Sept. 24, 2018
Comments: