-
-
Save Raynos/12a80ce2c6dc6afcabd8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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