Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
fix: native sort is stable now
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomrdias authored and vmx committed Apr 21, 2020
1 parent 98d9ac6 commit 3048e3e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/dag-node/sortLinks.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
'use strict'

const sort = require('stable')
const { Buffer } = require('buffer')

const linkSort = (a, b) => {
return Buffer.compare(a.nameAsBuffer, b.nameAsBuffer)
}

/**
*
* @param {Array} links
* @returns {Array}
*/
const sortLinks = (links) => {
return sort(links, linkSort)
return links.sort(linkSort)
}

module.exports = sortLinks

0 comments on commit 3048e3e

Please sign in to comment.