Skip to content

Instantly share code, notes, and snippets.

@Romanior
Created June 21, 2016 07:58
Show Gist options
  • Save Romanior/7cf8e773d84974d304aa4dfe291450e7 to your computer and use it in GitHub Desktop.
Save Romanior/7cf8e773d84974d304aa4dfe291450e7 to your computer and use it in GitHub Desktop.
module.exports = () => {
const _nodes = [];
return {
toString(){
return _nodes;
},
// array [ priority, key ]
set node(item) {
if (Array.isArray(item) && item.length === 2){
_nodes.push(item);
this._sort();
}
},
get node(){
return _nodes.shift()[1];
},
get isEmpty(){
return !_nodes.length;
},
_sort() {
_nodes.sort((a, b) => {
return a[0] - b[0];
});
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment