DEV Community

Discussion on: Daily Challenge #58 - Smelting Iron Ingots

Collapse
 
metcoder profile image
Carlos Fuentes

The challenge was a little bit ambiguous about the requirement. If I understand correctly, is asking about at least how many resources of each fuel you require to try to smelt iron ingots.
With this, I wrote the following solution in JavaScript

const calculateFuelForIrons = ironCubesQty => {
  const FUEL_DURATION = {
    lava: 800,
    blazeRod: 120,
    coal: 80,
    wood: 15,
    stick: 1
  };

  const smeltingTime = ironCubesQty * 11;

  return Object.keys(FUEL_DURATION).reduce((result, key) => {
    const newResult = {
      ...result,
      [key]: Math.floor(smeltingTime / FUEL_DURATION[key])
    };

    return { ...newResult };
  }, {});
};

console.log(calculateFuelForIrons(10));
console.log(calculateFuelForIrons(110));
console.log(calculateFuelForIrons(11000));
console.log(calculateFuelForIrons(0));