Skip to content

Commit

Permalink
Merge pull request #159 from ahasnawi/distance-sorting-issue
Browse files Browse the repository at this point in the history
considering distance units in sorting
  • Loading branch information
nteske authored Nov 1, 2021
2 parents f7cac29 + 56841af commit e3ee2e8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
20 changes: 12 additions & 8 deletions src/widget/js/PlacesSort.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,22 @@ window.PlacesSort = {
var aDistance = 0;
var bDistance = 0;
if (a.distance && b.distance) {
const aDist = a.distance.split(' ')[0];
const bDist = b.distance.split(' ')[0];
if (aDist.includes('.')) {
aDistance = parseInt(a.distance.split(' ')[0].replace('.', ''));
const aDist = a.distance.split(' ');
const bDist = b.distance.split(' ');
if (aDist[0].includes('.')) {
aDistance = parseInt(aDist[0].replace('.', ''));
} else {
aDistance = parseInt(a.distance.split(' ')[0].replace(',', ''));
aDistance = parseInt(aDist[0].replace(',', ''));
}
if (bDist.includes('.')) {
bDistance = parseInt(b.distance.split(' ')[0].replace('.', ''));
aDistance = aDist[1] === 'ft' ? aDistance / 5280 : aDistance;
aDistance = aDist[1] === 'm' ? aDistance / 1000 : aDistance;
if (bDist[0].includes('.')) {
bDistance = parseInt(bDist[0].replace('.', ''));
} else {
bDistance = parseInt(b.distance.split(' ')[0].replace(',', ''));
bDistance = parseInt(bDist[0].replace(',', ''));
}
bDistance = bDist[1] === 'ft' ? bDistance / 5280 : bDistance;
bDistance = bDist[1] === 'm' ? bDistance / 1000 : bDistance;

if (aDistance < bDistance) {
return -1;
Expand Down
6 changes: 5 additions & 1 deletion src/widget/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ window.app = {
});
let str = null;
if (distance < 0.5) {
str = Math.round(distance * 5280).toLocaleString() + " ft";
if (window.app.state.distanceUnit) {
str = Math.round(distance * 1609.34).toLocaleString() + " m";
} else {
str = Math.round(distance * 5280).toLocaleString() + " ft";
}
}
else {
if (window.app.state.distanceUnit) {
Expand Down

0 comments on commit e3ee2e8

Please sign in to comment.