File tree Expand file tree Collapse file tree 5 files changed +38
-6
lines changed Expand file tree Collapse file tree 5 files changed +38
-6
lines changed Original file line number Diff line number Diff line change
1
+ import assert from 'assert' ;
2
+ import Node from './Node.js' ;
3
+ import _remove from './_remove.js' ;
4
+
5
+ /**
6
+ * Removes last {@link Node} from a non-empty list.
7
+ *
8
+ * @param {Node } x First node (not null).
9
+ * @return {Node } New list (possibly null).
10
+ */
11
+ export default function _pop ( x ) {
12
+ assert ( x instanceof Node ) ;
13
+ if ( x === x . prev ) return null ;
14
+ _remove ( x . prev ) ;
15
+ return x ;
16
+ }
Original file line number Diff line number Diff line change
1
+ import assert from 'assert' ;
2
+ import Node from './Node.js' ;
3
+ import _remove from './_remove.js' ;
4
+
5
+ /**
6
+ * Removes first {@link Node} from a non-empty list.
7
+ *
8
+ * @param {Node } x First node (not null).
9
+ * @return {Node } New list (possibly null).
10
+ */
11
+ export default function _shift ( x ) {
12
+ assert ( x instanceof Node ) ;
13
+ if ( x === x . next ) return null ;
14
+ _remove ( x ) ;
15
+ return x . next ;
16
+ }
Original file line number Diff line number Diff line change @@ -4,7 +4,9 @@ export {default as _concat} from './_concat.js';
4
4
export { default as _iter } from './_iter.js' ;
5
5
export { default as _iter_fast } from './_iter_fast.js' ;
6
6
export { default as _len } from './_len.js' ;
7
+ export { default as _pop } from './_pop.js' ;
7
8
export { default as _remove } from './_remove.js' ;
9
+ export { default as _shift } from './_shift.js' ;
8
10
export { default as concat } from './concat.js' ;
9
11
export { default as empty } from './empty.js' ;
10
12
export { default as from } from './from.js' ;
Original file line number Diff line number Diff line change 1
1
import assert from 'assert' ;
2
2
import Node from './Node.js' ;
3
- import _remove from './_remove .js' ;
3
+ import _pop from './_pop .js' ;
4
4
5
5
/**
6
6
* Removes last {@link Node} from a list. Throws if input list is empty.
@@ -12,6 +12,5 @@ export default function pop(x) {
12
12
if ( x === null ) throw new Error ( 'input list is empty' ) ;
13
13
assert ( x instanceof Node ) ;
14
14
const node = x . prev ;
15
- _remove ( node ) ;
16
- return [ x === node ? null : x , node ] ;
15
+ return [ _pop ( x ) , node ] ;
17
16
}
Original file line number Diff line number Diff line change 1
1
import assert from 'assert' ;
2
2
import Node from './Node.js' ;
3
- import _remove from './_remove .js' ;
3
+ import _shift from './_shift .js' ;
4
4
5
5
/**
6
6
* Removes first {@link Node} from a list. Throws if input list is empty.
@@ -11,6 +11,5 @@ import _remove from './_remove.js';
11
11
export default function shift ( x ) {
12
12
if ( x === null ) throw new Error ( 'input list is empty' ) ;
13
13
assert ( x instanceof Node ) ;
14
- _remove ( x ) ;
15
- return [ x === x . next ? null : x . next , x ] ;
14
+ return [ _shift ( x ) , x ] ;
16
15
}
You can’t perform that action at this time.
0 commit comments