Comparing version 0.0.10 to 0.0.11
{ | ||
"name": "stac", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"description": "Maintain a sorted stack of things.", | ||
@@ -5,0 +5,0 @@ "main": "stac.js", |
22
stac.js
function Stac(options) { | ||
var self = this; | ||
var self = this | ||
, toAdd = null; | ||
options = options || {}; | ||
if (Array.isArray(options)) { | ||
toAdd = options; | ||
options = {}; | ||
} | ||
this._options = options; | ||
this._stack = []; | ||
this._sorted = false; | ||
this._stack = []; | ||
this._sortBy = options.sortBy || 'weight'; | ||
this._defaultVal = options.defaultVal || 0; | ||
this._options = options || {}; | ||
this._sortBy = this._options.sortBy || 'weight'; | ||
this._defaultVal = this._options.defaultVal || 0; | ||
this._comparator = options.comparator || function comparator (a, b) { | ||
this._comparator = this._options.comparator || function comparator (a, b) { | ||
if (a === b) return 0; | ||
@@ -21,2 +25,6 @@ return a < b ? -1 : 1; | ||
}); | ||
if (toAdd) { | ||
this.multi('add', toAdd); | ||
} | ||
} | ||
@@ -23,0 +31,0 @@ |
@@ -202,3 +202,9 @@ var createStac = require('../'); | ||
it('can be created with an existing array', function () { | ||
stack = createStac(['A', 'B', 'C', 'D']); | ||
assert.equal(stack.pop(), 'D'); | ||
assert.equal(stack.shift(), 'A'); | ||
}); | ||
}); | ||
14125
308