Skip to content

Instantly share code, notes, and snippets.

@leepfrog
Forked from devinus/gist:3541920
Created August 31, 2012 18:44
Show Gist options
  • Save leepfrog/3557191 to your computer and use it in GitHub Desktop.
Save leepfrog/3557191 to your computer and use it in GitHub Desktop.
// In this sorting function, we have three indices in our array
// a[0] - the name of the injection
// a[1] - the name of an injection that THIS injection should be before
// a[2] - the name of an injection that THIS injection should be after
// When given an array:
// [['b', 'c', null], ['a','b', null], ['d', null, 'c'], ['c', null, null], ['e', null, 'd']];
// Then the output from this array should look like:
// [['a','b', null], ['b', 'c', null], ['c', null, null], ['d', null, 'c'], ['e', null, 'd']];
// We are assuming:
// The injection should either have a before OR an after, not both
// If an injection utilizes the same name/object for a before or after target, then the injections should be considered to be un-ordered within that set
// Here are the rules for the sort:
// #1 an injection with a before target should appear before any other injection
// and that injection should appear before it's named target
// #2 an injection with an after target should appear after any other injection
// and that injection should appear after it's named target
var injections = [['b', 'c', null], ['a','b', null], ['d', null, 'c'], ['c', null, null], ['e', null, 'd']];
@leepfrog
Copy link
Author

Updated so you have a place to track

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment