File tree Expand file tree Collapse file tree 4 files changed +45
-24
lines changed Expand file tree Collapse file tree 4 files changed +45
-24
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,7 @@ describe('Stack', () => {
64
64
it ( 'get helpers make for easier to read code' , ( ) => {
65
65
var s = Stack . of ( 'a' , 'b' , 'c' ) ;
66
66
expect ( s . first ( ) ) . toBe ( 'a' ) ;
67
+ expect ( s . last ( ) ) . toBe ( 'c' ) ;
67
68
expect ( s . peek ( ) ) . toBe ( 'a' ) ;
68
69
} ) ;
69
70
@@ -83,7 +84,14 @@ describe('Stack', () => {
83
84
[ 1 , 'b' ] ,
84
85
[ 2 , 'c' ] ,
85
86
] ) ;
86
-
87
+
88
+ // map will cause reverse iterate
89
+ expect ( s . map ( val => val + val ) . toArray ( ) ) . toEqual ( [
90
+ 'aa' ,
91
+ 'bb' ,
92
+ 'cc' ,
93
+ ] ) ;
94
+
87
95
var iteratorResults = [ ] ;
88
96
var iterator = s . entries ( ) ;
89
97
var step ;
@@ -95,6 +103,17 @@ describe('Stack', () => {
95
103
[ 1 , 'b' ] ,
96
104
[ 2 , 'c' ] ,
97
105
] ) ;
106
+
107
+ iteratorResults = [ ] ;
108
+ iterator = s . toSeq ( ) . reverse ( ) . entries ( ) ;
109
+ while ( ! ( step = iterator . next ( ) ) . done ) {
110
+ iteratorResults . push ( step . value ) ;
111
+ }
112
+ expect ( iteratorResults ) . toEqual ( [
113
+ [ 0 , 'c' ] ,
114
+ [ 1 , 'b' ] ,
115
+ [ 2 , 'a' ] ,
116
+ ] ) ;
98
117
} ) ;
99
118
100
119
it ( 'push inserts at lowest index' , ( ) => {
Original file line number Diff line number Diff line change 3278
3278
3279
3279
Stack . prototype . get = function ( index , notSetValue ) {
3280
3280
var head = this . _head ;
3281
+ index = wrapIndex ( this , index ) ;
3281
3282
while ( head && index -- ) {
3282
3283
head = head . next ;
3283
3284
}
3410
3411
3411
3412
Stack . prototype . __iterate = function ( fn , reverse ) {
3412
3413
if ( reverse ) {
3413
- return this . toSeq ( ) . cacheResult . __iterate ( fn , reverse ) ;
3414
+ return this . reverse ( ) . __iterate ( fn ) ;
3414
3415
}
3415
3416
var iterations = 0 ;
3416
3417
var node = this . _head ;
3425
3426
3426
3427
Stack . prototype . __iterator = function ( type , reverse ) {
3427
3428
if ( reverse ) {
3428
- return this . toSeq ( ) . cacheResult ( ) . __iterator ( type , reverse ) ;
3429
+ return this . reverse ( ) . __iterator ( type ) ;
3429
3430
}
3430
3431
var iterations = 0 ;
3431
3432
var node = this . _head ;
You can’t perform that action at this time.
0 commit comments