diff --git a/src/BaseInput.js b/src/BaseInput.js index c29adf9..fe301e2 100644 --- a/src/BaseInput.js +++ b/src/BaseInput.js @@ -54,13 +54,15 @@ function isChronological(list) { } -function generateCombinations(dictionary) { +function generateCombinations(dictionary, conditionFn) { const keys = Object.keys(dictionary); const result = []; function backtrack(combination, index) { if (index === keys.length) { - result.push([...combination]); + if (conditionFn(combination)) { + result.push([...combination]); + } return; } @@ -78,6 +80,7 @@ function generateCombinations(dictionary) { return result; } + // Convert degrees to radians function degreesToRadians(degrees) { return degrees * Math.PI / 180; @@ -253,14 +256,12 @@ const BaseInput = forwardRef(({ setConcerts, // thanks stackoverflow, I'm not writing up this shit. // https://stackoverflow.com/questions/4331092/finding-all-combinations-cartesian-product-of-javascript-array-values // this needs to be a list of list - var allCombinationOfConcerts = generateCombinations(groupedByArtistConcertList); - //now filter out the ones that don't make chronological sense - allCombinationOfConcerts = allCombinationOfConcerts.filter(isChronological); + var allCombinationOfConcerts = generateCombinations(groupedByArtistConcertList, isChronological); if (allCombinationOfConcerts.length < 1) { alert(`Unable to schedule a plan for the artist concerts you want to go, their schedules conflict with each other`); //remove the last attempted artist that was causing problem and run the optimization again - generateOptimizedConcertRoute(allConcerts,userLocation, artistWishlist.pop()); + generateOptimizedConcertRoute(allConcerts, userLocation, artistWishlist.pop()); } //now sort the remaining by max distance traveled