Skip to content

Commit 5ba1c31

Browse files
authored
Normalize (#150)
* add failing test * fixed failure
1 parent 460afb5 commit 5ba1c31

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/buildingpart.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,14 +360,14 @@ class BuildingPart {
360360
// remove final character.
361361
return parseFloat(length.substring(0, length.length - 2)) * 1000;
362362
}
363-
if (length.includes('mi')){
364-
// remove final character.
365-
return parseFloat(length.substring(0, length.length - 2)) * 5280 * 12 * 2.54 / 100;
366-
}
367363
if (length.includes('nmi')){
368364
// remove final character.
369365
return parseFloat(length.substring(0, length.length - 3)) * 1852;
370366
}
367+
if (length.includes('mi')){
368+
// remove final character.
369+
return parseFloat(length.substring(0, length.length - 2)) * 5280 * 12 * 2.54 / 100;
370+
}
371371
if (length.includes('m')){
372372
// remove final character.
373373
return parseFloat(length.substring(0, length.length - 1));

test/buildingpart.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ test('Constructor', () => {
6767
expect(errors.length).toBe(0);
6868
});
6969

70+
test('Normalize Length', () => {
71+
expect(BuildingPart.normalizeLength('5km')).toBe(5000);
72+
expect(BuildingPart.normalizeLength('1mi')).toBe(1609.344);
73+
expect(BuildingPart.normalizeLength('1nmi')).toBe(1852);
74+
});
75+
7076
window.printError = printError;
7177

7278
var errors = [];

0 commit comments

Comments
 (0)