[openstreetmap/openstreetmap-website] Take entrances into account for routing start and end points (PR #7017)
Marwin Hochfelsner
notifications at github.com
Thu Apr 23 00:31:42 UTC 2026
@hlfan commented on this pull request.
> +
+ let bestFind = types.length;
+ let result = null;
+
+ for (const e of entrances) {
+ const matchId = types.indexOf(e.type);
+ if (matchId === 0) return e;
+ if (matchId > 0 && matchId < bestFind) {
+ bestFind = matchId;
+ result = e;
+ }
+ }
+
+ return result;
So I've been summoned to add my two cents.
Instead, I'm giving you yet another variant that optimises asymptotic behavior while not trashing readability.
```suggestion
const map = {};
for (const e of entrances) if (!map[e.type]) map[e.type] = e;
for (const type of types) if (map[type]) return map[type];
return null;
```
--
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/7017?email_source=notifications&email_token=AAK2OLJCMRIF7U3AVHSEQ2T4XFP65A5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTIMJVHA3TANRQGQ3KM4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOS6XA4S7OJSXM2LFO5PW433UNFTGSY3BORUW63TTL5RWY2LDNM#pullrequestreview-4158706046
You are receiving this because you are subscribed to this thread.
Message ID: <openstreetmap/openstreetmap-website/pull/7017/review/4158706046 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20260422/8d9a39a4/attachment.htm>
More information about the rails-dev
mailing list