File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
lib/data-structures/stacks Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,13 @@ class Stack {
3232 get size ( ) {
3333 return this . input . size ;
3434 }
35+
36+ /**
37+ * Return true if is empty false otherwise true
38+ */
39+ isEmpty ( ) {
40+ return ! this . input . size ;
41+ }
3542}
3643
3744// aliases
Original file line number Diff line number Diff line change @@ -27,4 +27,17 @@ describe('Stack', function () {
2727 expect ( stack . pop ( ) ) . toEqual ( undefined ) ;
2828 } ) ;
2929 } ) ;
30+
31+ describe ( '#isEmpty' , ( ) => {
32+ it ( 'should return true when empty' , ( ) => {
33+ // expect(stack.size).toBe(0);
34+ expect ( stack . isEmpty ( ) ) . toBe ( true ) ;
35+ } ) ;
36+
37+ it ( 'should return false when not empty' , ( ) => {
38+ stack . add ( 'a' ) ;
39+ // expect(stack.size).toBe(1);
40+ expect ( stack . isEmpty ( ) ) . toBe ( false ) ;
41+ } ) ;
42+ } ) ;
3043} ) ;
You can’t perform that action at this time.
0 commit comments