Skip to content

Commit

Permalink
fix sorting issue in newsletterWorker. Closes #5
Browse files Browse the repository at this point in the history
  • Loading branch information
juliaqiuxy committed Jan 23, 2018
1 parent 8157f16 commit f648eb8
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/workers/newslettersWorker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,39 +58,39 @@ export const run = async () => {
return;
}

const resortRows = resorts.map((resort) => {
return {
resortName: resort.name,
resortUrl: `http://slope.ninja/resorts/${resort.shortName}`,
newSnow: resort.weather.newSnow !== null ? `${resort.weather.newSnow}"` : '-',
snowDepth: resort.weather.snowDepth !== null ? `${resort.weather.snowDepth}"` : '-',
weatherIconUrl: WEATHER_ICONS[resort.weather.condition],
resortLogoUrl: RESORT_LOGOS[resort.shortName],
};
});

resortRows.sort((a, b) => {
if (a.snowDepth < b.snowDepth) {
resorts.sort((a, b) => {
if (a.weather.snowDepth < b.weather.snowDepth) {
return 1;
}
if (a.snowDepth > b.snowDepth) {
if (a.weather.snowDepth > b.weather.snowDepth) {
return -1;
}

return 0;
});

resortRows.sort((a, b) => {
if (a.newSnow < b.newSnow) {
resorts.sort((a, b) => {
if (a.weather.newSnow < b.weather.newSnow) {
return 1;
}
if (a.newSnow > b.newSnow) {
if (a.weather.newSnow > b.weather.newSnow) {
return -1;
}

return 0;
});

const resortRows = resorts.map((resort) => {
return {
resortName: resort.name,
resortUrl: `http://slope.ninja/resorts/${resort.shortName}`,
newSnow: resort.weather.newSnow !== null ? `${resort.weather.newSnow}"` : '-',
snowDepth: resort.weather.snowDepth !== null ? `${resort.weather.snowDepth}"` : '-',
weatherIconUrl: WEATHER_ICONS[resort.weather.condition],
resortLogoUrl: RESORT_LOGOS[resort.shortName],
};
});

const now = moment();
const currentDateFormatted = now.format('MMMM Do, YYYY');
const dateTimeFormatted = `${currentDateFormatted} 1:00 PM`;
Expand Down

0 comments on commit f648eb8

Please sign in to comment.