Skip to content

Commit 7099e12

Browse files
feat(2019-01): calculate fuel from mass ratios
1 parent 9d0af42 commit 7099e12

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const calculateFuel = (mass) => {
2+
return Math.floor(mass / 3) - 2
3+
}
4+
5+
module.exports = {
6+
calculateFuel
7+
}

2019/day-01/part-1/fuel-calculator.test.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
const expect = require('chai').expect
33
const { calculateFuel } = require('./fuel-calculator')
44

5-
describe('2019 Day 01', () => {
6-
it('calculates the fuel amount for a specified mass', () => {
7-
const inputs = [12, 14, 1969, 100756]
8-
const outputs = [2, 2, 654, 33583]
5+
describe('--- 2019 Day 1: The Tyranny of the Rocket Equation ---', () => {
6+
describe('Part 1', () => {
7+
it('calculates the fuel amount for a specified mass', () => {
8+
const inputs = [12, 14, 1969, 100756]
9+
const outputs = [2, 2, 654, 33583]
910

10-
inputs.forEach((input, idx) => {
11-
console.log(input)
12-
expect(calculateFuel(input)).equals(outputs[idx])
11+
inputs.forEach((input, idx) => {
12+
expect(calculateFuel(input)).equals(outputs[idx])
13+
})
1314
})
1415
})
1516
})

0 commit comments

Comments
 (0)