Skip to content

Commit

Permalink
remove useless time filter method
Browse files Browse the repository at this point in the history
  • Loading branch information
sam9116 committed Feb 12, 2024
1 parent 8ec1b2e commit 16dd5eb
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/BaseInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const BaseInput = forwardRef(({ setConcerts, setUserLocation, setMapStyle, start
const sortArtist = (incomingAllConcerts, userLocation) => {
console.log(`total Number Of Concerts Memorized after submitArtist: ${incomingAllConcerts.length}`);
console.log(`sort all concerts`);

incomingAllConcerts = incomingAllConcerts.sort((a, b) => {
return (new Date(a.date) - new Date(b.date));
});
Expand All @@ -142,22 +143,28 @@ const BaseInput = forwardRef(({ setConcerts, setUserLocation, setMapStyle, start
return (distancea - distanceb);
})

console.log(`filter the sorted concert by date , so we're only left with no more than 1 concert on the same date `);
console.log(`filter the sorted concert by artist name, so we're only left with one concert per artist`);
var newConcerts = incomingAllConcerts.filter((value, index, self) => {
return self.findIndex((v) => {
return self.findIndex(v => v.artist === value.artist || v.title == value.title) === index;
});

var vDate = new Date(v.date).toDateString();
var valueDate = new Date(value.date).toDateString();
var concertTitles = newConcerts.map(concert => concert.title);
newConcerts = newConcerts.filter((concert) => {

return vDate.valueOf() == valueDate.valueOf();
}) === index;
});
var match = false;

concertTitles.forEach((concertTitle) => {
if (concertTitle.toLowerCase().includes(concert.artist.toLowerCase())) {
match = true;
}
});

return match;

console.log(`filter the sorted concert by artist name, so we're only left with one concert per artist`);
newConcerts = newConcerts.filter((value, index, self) => {
return self.findIndex(v => v.artist === value.artist || v.title == value.title) === index;
});



newConcerts = newConcerts.sort((a, b) => { return (new Date(a.date) - new Date(b.date)) });
console.log(`concat the new concerts into the optimized list`);
setConcerts(newConcerts);
Expand Down

0 comments on commit 16dd5eb

Please sign in to comment.