Created
June 21, 2016 07:58
-
-
Save Romanior/7cf8e773d84974d304aa4dfe291450e7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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