mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2026-03-13 08:51:02 +08:00
Make it possible to add objects to LinkedList.
This commit is contained in:
@@ -13,7 +13,7 @@ describe('Stack', () => {
|
||||
stack.push(1);
|
||||
stack.push(2);
|
||||
|
||||
expect(stack.linkedList.toString()).toBe('1,2');
|
||||
expect(stack.toString()).toBe('1,2');
|
||||
});
|
||||
|
||||
it('should peek data from stack', () => {
|
||||
@@ -49,4 +49,17 @@ describe('Stack', () => {
|
||||
expect(stack.pop()).toBeNull();
|
||||
expect(stack.isEmpty()).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should be possible to push/pop objects', () => {
|
||||
const stack = new Stack();
|
||||
|
||||
stack.push({ value: 'test1', key: 'key1' });
|
||||
stack.push({ value: 'test2', key: 'key2' });
|
||||
|
||||
const stringifier = value => `${value.key}:${value.value}`;
|
||||
|
||||
expect(stack.toString(stringifier)).toBe('key1:test1,key2:test2');
|
||||
expect(stack.pop().value).toBe('test2');
|
||||
expect(stack.pop().value).toBe('test1');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user