Skip to content

Instantly share code, notes, and snippets.

@Raynos
Created January 15, 2013 07:14
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 Raynos/12a80ce2c6dc6afcabd8 to your computer and use it in GitHub Desktop.
Save Raynos/12a80ce2c6dc6afcabd8 to your computer and use it in GitHub Desktop.
var append = require("insert/append")
var before = require("insert/before")
module.exports = Ordered
function Ordered(parent) {
var hash = {}
return function insert(key, elem) {
var keys = Object.keys(hash)
var after = keys.filter(function (other) {
return other > key
})[0]
var target = hash[after] || null
if (target === null) {
append(parent, elem)
} else {
before(target, elem)
}
hash[key] = elem
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment