File tree Expand file tree Collapse file tree 7 files changed +55
-24
lines changed Expand file tree Collapse file tree 7 files changed +55
-24
lines changed Original file line number Diff line number Diff line change 33 * 
44 * @class  
55 * @param  {any } value The value to hold. 
6+  * @param  {Node|null } prev The value to hold. 
7+  * @param  {Node|null } next The value to hold. 
68 */ 
7- export  default  function  Node ( value )  { 
9+ // eslint-disable-next-line unicorn/prevent-abbreviations 
10+ export  default  function  Node ( value ,  prev ,  next )  { 
811	/** @member  {any} The value/key held by this node. */ 
912	this . value  =  value ; 
10- 	/** @member  {Node} Pointer to previous (left) sibling */ 
11- 	this . prev  =  null ; 
12- 	/** @member  {Node} Pointer to next (right) sibling */ 
13- 	this . next  =  null ; 
13+ 	/** @member  {Node|null } Pointer to previous (left) sibling */ 
14+ 	this . prev  =  prev ; 
15+ 	/** @member  {Node|null } Pointer to next (right) sibling */ 
16+ 	this . next  =  next ; 
1417} 
Original file line number Diff line number Diff line change 1+ import  assert  from  'assert' ; 
2+ import  Node  from  './Node.js' ; 
3+ 
4+ /** 
5+  * Push value to list. 
6+  * 
7+  * @param  {Node } z Last node of first input list (can be null). 
8+  * @param  {any } value Value to push. 
9+  * @return  {Node } The node at the front of the list (new node if empty, input 
10+  * node otherwise). 
11+  */ 
12+ export  default  function  _push ( z ,  value )  { 
13+ 	assert ( z  instanceof  Node ) ; 
14+ 	assert ( z . next  ===  null ) ; 
15+ 	const  y  =  new  Node ( value ,  z ,  null ) ; 
16+ 	z . next  =  y ; 
17+ 	return  y ; 
18+ } 
Original file line number Diff line number Diff line change 1+ import  assert  from  'assert' ; 
2+ import  Node  from  './Node.js' ; 
3+ 
4+ /** 
5+  * Unshift value to list. 
6+  * 
7+  * @param  {Node } x First node of first input list (can be null). 
8+  * @param  {any } value Value to unshift. 
9+  * @return  {Node } The node at the front of the list (hence, the new node). 
10+  */ 
11+ export  default  function  _unshift ( x ,  value )  { 
12+ 	assert ( x  instanceof  Node ) ; 
13+ 	assert ( x . prev  ===  null ) ; 
14+ 	const  y  =  new  Node ( value ,  null ,  x ) ; 
15+ 	x . prev  =  y ; 
16+ 	return  y ; 
17+ } 
Original file line number Diff line number Diff line change 11import  Node  from  './Node.js' ; 
2- import  _concat  from  './_concat .js' ; 
2+ import  _push  from  './_push .js' ; 
33
44/** 
55 * Creates a list from an input iterable. 
@@ -13,13 +13,11 @@ export default function from(iterable) {
1313
1414	if  ( event . done )  return  null ; 
1515
16- 	const  first  =  new  Node ( event . value ) ; 
16+ 	const  first  =  new  Node ( event . value ,   null ,   null ) ; 
1717	let  last  =  first ; 
1818
1919	for  ( const  value  of  it )  { 
20- 		const  next  =  new  Node ( value ) ; 
21- 		_concat ( last ,  next ) ; 
22- 		last  =  next ; 
20+ 		last  =  _push ( last ,  value ) ; 
2321	} 
2422
2523	return  first ; 
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ export {default as _iter_fast} from './_iter_fast.js';
55export  { default  as  _last }  from  './_last.js' ; 
66export  { default  as  _len }  from  './_len.js' ; 
77export  { default  as  _pop }  from  './_pop.js' ; 
8+ export  { default  as  _push }  from  './_push.js' ; 
89export  { default  as  _remove }  from  './_remove.js' ; 
910export  { default  as  _rotate_left }  from  './_rotate_left.js' ; 
1011export  { default  as  _rotate_left_modulo }  from  './_rotate_left_modulo.js' ; 
@@ -15,6 +16,7 @@ export {default as _rotate_right_unknown_length} from './_rotate_right_unknown_l
1516export  { default  as  _rotate_to }  from  './_rotate_to.js' ; 
1617export  { default  as  _shift }  from  './_shift.js' ; 
1718export  { default  as  _split }  from  './_split.js' ; 
19+ export  { default  as  _unshift }  from  './_unshift.js' ; 
1820export  { default  as  concat }  from  './concat.js' ; 
1921export  { default  as  empty }  from  './empty.js' ; 
2022export  { default  as  from }  from  './from.js' ; 
Original file line number Diff line number Diff line change 11import  assert  from  'assert' ; 
22import  Node  from  './Node.js' ; 
3- import  _concat  from  './_concat .js' ; 
3+ import  _push  from  './_push .js' ; 
44
55/** 
66 * Push value to list. 
@@ -12,11 +12,8 @@ import _concat from './_concat.js';
1212 * node otherwise). 
1313 */ 
1414export  default  function  push ( x ,  z ,  value )  { 
15- 	if  ( x  ===  null )  return  new  Node ( value ) ; 
15+ 	if  ( x  ===  null )  return  new  Node ( value ,   null ,   null ) ; 
1616	assert ( x  instanceof  Node ) ; 
17- 	assert ( z  instanceof  Node ) ; 
18- 	assert ( z . next  ===  null ) ; 
19- 	const  y  =  new  Node ( value ) ; 
20- 	_concat ( z ,  y ) ; 
17+ 	_push ( z ,  value ) ; 
2118	return  x ; 
2219} 
Original file line number Diff line number Diff line change 1- import  assert  from  'assert' ; 
21import  Node  from  './Node.js' ; 
3- import  _concat  from  './_concat .js' ; 
2+ import  _unshift  from  './_unshift .js' ; 
43
54/** 
65 * Unshift value to list. 
76 * 
87 * @param  {Node } x First node of first input list (can be null). 
9-  * @param  {Object } value Value to unshift. 
8+  * @param  {any } value Value to unshift. 
109 * @return  {Node } The node at the front of the list (hence, the new node). 
1110 */ 
1211export  default  function  unshift ( x ,  value )  { 
13- 	if  ( x  ===  null )  return  new  Node ( value ) ; 
14- 	assert ( x  instanceof  Node ) ; 
15- 	const  y  =  new  Node ( value ) ; 
16- 	_concat ( y ,  x ) ; 
17- 	return  y ; 
12+ 	if  ( x  ===  null )  return  new  Node ( value ,  null ,  null ) ; 
13+ 	return  _unshift ( x ,  value ) ; 
1814} 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments