Skip to content

Instantly share code, notes, and snippets.

@DanyelMorales
Created December 12, 2018 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanyelMorales/d6d5f8238665a363da9493ad04043d5e to your computer and use it in GitHub Desktop.
Save DanyelMorales/d6d5f8238665a363da9493ad04043d5e to your computer and use it in GitHub Desktop.
sort by group ASC, name ASC, version DESC
var semver = require("semver");
var blocks = [{group:"", name:"", version:""},{group:"", name:"", version:""}]
// sort by group ASC, name ASC, version DESC
blocks.sort(function(a, b) {
var nameA = a.group + a.name;
var nameB = b.group + b.name;
if (nameA === nameB) {
if (a.version === b.version)
return 0;
return (semver.gte(a.version, b.version)) ? -1 : 1;
}
return (nameA < nameB) ? -1 : 1;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment