Nautical mile option in Units-Editor#1059
Conversation
In Distance --> Distance Unit.
✅ Deploy Preview for afmg ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
|
The "league" unit in distance has the numbers of a nautical league. function toKilometer(v) {
if (unit === "km") return v;
else if (unit === "mi") return v * 1.60934;
else if (unit === "lg") return v * 4.828;
else if (unit === "vr") return v * 1.0668;
else if (unit === "nmi") return v * 1.852;
else if (unit === "nlg") return v * 5.556;
return 0; // 0 if distanceUnitInput is a custom unit
}and the HTML like: <div data-tip="Select a distance unit or provide a custom name">
<div>Distance unit:</div>
<select id="distanceUnitInput" data-stored="distanceUnit">
<option value="mi" selected>Mile (mi)</option>
<option value="km">Kilometer (km)</option>
<option value="lg">League (lg)</option>
<option value="vr">Versta (vr)</option>
<option value="nmi">Nautical mile (nmi)</option>
<option value="nlg">Nautical league (nlg)</option>
<option value="custom_name">Custom name</option>
</select>
</div> |
I would like to suggest the following refactor of the toKilometer Function for possibile expansions in the future : function toKilometer(v) {
switch(unit) {
case 'km': return v;
case 'mi': return v * 1.60934;
case 'lg': return v * 4.828;
case 'vr': return v * 1.0668;
case 'nmi': return v * 1.852;
case 'nlg': return v * 5.556;
default: return 0; // 0 if distanceUnitInput is a custom unit
}
}No |
I don't see how it's better. If with earlier exit can be simpler than switch. |
|
Azgaar, what's your decision on this added code?
Also, do we put the switch or the list of else ifs? |
|
It's fine, you can add. The code should be like that: function toKilometer(v) {
if (unit === "km") return v;
if (unit === "mi") return v * 1.60934;
if (unit === "lg") return v * 5.556;
if (unit === "vr") return v * 1.0668;
return 0;
}
|
The distance 5.556 km = 1 league, is put on the nautical league and used the English land league 4.828 to differentiate both units.
|
I'm ok to merge, please update the version |
changed 1.97.02 to 1.97.03
|
@Avengium, hm, not that way. Now there is a conflict. Also need to update hash for changed scripts in index.html. |
in hopes of fixing the version conflict
Description
I added nautical mile as an option for Units Editor. In Distance --> Distance Unit.
Type of change
New option in dropdown distance unit.
Versioning