Skip to content

Commit

Permalink
Merge pull request #21 from collective/fix_getItemsByPath
Browse files Browse the repository at this point in the history
fix: getItemsByPath sorting stability
  • Loading branch information
nzambello authored Apr 21, 2021
2 parents 6296feb + 32822f0 commit 3bb101a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export function getItemsByPath(items, pathname) {
const matchingPaths = Object.keys(itemsByPath)
.filter((path) => pathname.startsWith(path))
.sort((a, b) => {
return a.length < b.length;
if (a.length > b.length) return -1;
else if (a.length < b.length) return 1;
else return 0;
});

if (matchingPaths.length > 0) return itemsByPath[matchingPaths[0]].items;
Expand Down

0 comments on commit 3bb101a

Please sign in to comment.