Still struggling with this massive amount of gtfs data that thwarted every attempt to process it automatically. But eventually seeing some light at the end of the tunnel. So I’m coming back to the issue of filtering the data.
I really like the idea of sorting the array by length as you did and refactored my code accordingly. But I did not understand how sorting the array ahead of time is useful in your example. You use a for loop, so you loop through each item anyway, what did I miss here?
I absolutely like the idea though and extended my second approach with this feature using ids rather than names:
trainLines.sort((a, b) => b.length - a.length); const trainLineStopIdsArrCopy = trainLines.map(trainLineArr => trainLineArr.map(trainStop => trainStop.id)); const returnArrayOfTrainStopIds = arr => arr.map(trainStop => trainStop.id); const uniqueJourneys = trainLines.filter((trainLineArr, index) => !(returnArrayOfTrainStopIds(trainLineArr).every(trainLineStop => trainLineStopIdsArrCopy.slice(0, index).find(trainLineStopArrCopy => // slicing the array so I have to iterate only over the previous shorter arrays trainLineStopArrCopy.includes(trainLineStop)))));