diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a33752e..a3d30b8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Adding `StaticIntervalTree`. * Adding `PointerVector`. +* Adding `Stack.of`. * Improving `Vector` & `BitVector` reallocation performance. * Improving `InvertedIndex` performance. diff --git a/stack.js b/stack.js index 7bd78691..50d638de 100644 --- a/stack.js +++ b/stack.js @@ -190,6 +190,17 @@ Stack.from = function(iterable) { return stack; }; +/** + * Static @.of function taking an abitrary number of arguments & converting it + * into a stack. + * + * @param {...any} args + * @return {Stack} + */ +Stack.of = function() { + return Stack.from(arguments); +}; + /** * Exporting. */ diff --git a/test/stack.js b/test/stack.js index 7b2e4d94..b9398ad6 100644 --- a/test/stack.js +++ b/test/stack.js @@ -88,6 +88,12 @@ describe('Stack', function() { assert.deepEqual(stack.toArray(), [3, 2, 1]); }); + it('should be possible to create a stack from arbitrary arguments.', function() { + var stack = Stack.of(1, 2, 3); + + assert.deepEqual(stack.toArray(), [3, 2, 1]); + }); + it('should be possible to create a values iterator.', function() { var stack = Stack.from([1, 2, 3]);