Skip to content

Commit b22c433

Browse files
authored
Merge pull request #23 from nshiab/add-humidex
update getHumidex for humidex < temperature
2 parents 5b5e9db + ef9b6fd commit b22c433

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/weather/getHumidex.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**
2-
* Calculate Humidex Factor in Celsius given the temperature in Celsius and humidity percentage
2+
* Calculate Humidex Factor in Celsius given the temperature in Celsius and humidity percentage.
3+
* In case the calculated humidex is less than the given temperature, it returns temperature itself.
34
* ```js
45
* const humidex = getHumidex(30, 70); // returns 41
56
* ```
@@ -23,5 +24,6 @@ export default function getHumidex(
2324
const eTd = (eTs * humidity) / 100
2425
const humidex = Math.round(temperature + ((eTd - 10) * 5) / 9)
2526

27+
if (humidex < temperature) return temperature
2628
return humidex
2729
}

test/weather/getHumidex.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,26 @@ import assert from "assert"
22
import getHumidex from "../../src/weather/getHumidex.js"
33

44
describe("getHumidex", () => {
5-
it("should return the humidex (41) given temperature (30 C) and humidity (%70)", () => {
5+
it("should return the humidex (41) given temperature (30 C) and humidity (70%)", () => {
66
const humidex = getHumidex(30, 70)
77
assert.equal(humidex, 41)
88
})
9-
it("should return the humidex (29) given temperature (21 C) and humidity (%100)", () => {
9+
it("should return the humidex (29) given temperature (21 C) and humidity (100%)", () => {
1010
const humidex = getHumidex(21, 100)
1111
assert.equal(humidex, 29)
1212
})
13-
it("should return the humidex (47) given temperature (43 C) and humidity (%20)", () => {
13+
it("should return the humidex (47) given temperature (43 C) and humidity (20%)", () => {
1414
const humidex = getHumidex(43, 20)
1515
assert.equal(humidex, 47)
1616
})
17-
it("should return the humidex (59) given temperature (35 C) and humidity (%95)", () => {
17+
it("should return the humidex (59) given temperature (35 C) and humidity (95%)", () => {
1818
const humidex = getHumidex(35, 95)
1919
assert.equal(humidex, 59)
2020
})
21+
it("should return the temperature (21 C) (with humidity (20%)) if humidex is less than the temperature", () => {
22+
const humidex = getHumidex(21, 20)
23+
assert.equal(humidex, 21)
24+
})
2125
it("should throw error when humidex is not between 0 and 100", () => {
2226
assert.throws(() => getHumidex(30, 105))
2327
})

0 commit comments

Comments
 (0)