Skip to content

Commit 16844f9

Browse files
fix: correct mph2Beaufort algorithm
- Use entries() to get index and value correctly - Previous code iterated over values and used them as indices - Fix incorrect JSDoc comment (was ms2Beaufort, now mph2Beaufort)
1 parent f3e3603 commit 16844f9

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

MMM-OneCallWeather.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -865,22 +865,21 @@ Module.register("MMM-OneCallWeather", {
865865
},
866866

867867
/*
868-
* ms2Beaufort(ms)
869-
* Converts m2 to beaufort (windspeed).
868+
* mph2Beaufort(mph)
869+
* Converts mph to beaufort (windspeed).
870870
*
871871
* see:
872872
* https://www.spc.noaa.gov/faq/tornado/beaufort.html
873873
* https://en.wikipedia.org/wiki/Beaufort_scale#Modern_scale
874874
*
875-
* argument ms number - Windspeed in m/s.
875+
* argument mph number - Windspeed in mph.
876876
*
877877
* return number - Windspeed in beaufort.
878878
*/
879879
mph2Beaufort(mph) {
880880
const kmh = mph * 1.60934;
881881
const speeds = [1, 5, 11, 19, 28, 38, 49, 61, 74, 88, 102, 117, 1000];
882-
for (const beaufort of speeds) {
883-
const speed = speeds[beaufort];
882+
for (const [beaufort, speed] of speeds.entries()) {
884883
if (speed > kmh) {
885884
return beaufort;
886885
}

0 commit comments

Comments
 (0)