chain-lightning
Advanced tools
@@ -56,2 +56,10 @@ /* | ||
| // Array.prototype.includes() uses this for value equality | ||
| // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes | ||
| function isIdenticalTo( x , y ) { | ||
| return x === y || ( Number.isNaN( x ) && Number.isNaN( y ) ) ; | ||
| } | ||
| List.prototype.values = function *() { | ||
@@ -94,10 +102,18 @@ var current = this.head ; | ||
| // Array.prototype.includes() uses this for value equality | ||
| // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes | ||
| function isIdenticalTo( x , y ) { | ||
| return x === y || ( Number.isNaN( x ) && Number.isNaN( y ) ) ; | ||
| } | ||
| // Similar to .keys() | ||
| List.prototype.slots = function slots() { | ||
| var slots = new Array( this.length ) , | ||
| index = 0 , | ||
| current = this.head ; | ||
| while ( current ) { | ||
| slots[ index ++ ] = current ; | ||
| current = current.next ; | ||
| } | ||
| return slots ; | ||
| } ; | ||
| List.prototype.push = | ||
@@ -104,0 +120,0 @@ List.prototype.append = function append( ... elements ) { |
+1
-1
| { | ||
| "name": "chain-lightning", | ||
| "version": "0.2.0", | ||
| "version": "0.2.1", | ||
| "description": "Linked list", | ||
@@ -5,0 +5,0 @@ "main": "lib/chainlightning.js", |
@@ -202,2 +202,29 @@ /* | ||
| it( ".slots()" , () => { | ||
| var slots ; | ||
| var list , | ||
| e1 = { v: 'jack' } , | ||
| e2 = { v: 'bob' } , | ||
| e3 = { v: 'steve' } , | ||
| e4 = { v: 'bobby' } ; | ||
| list = new List( e1 , e2 , e3 ) ; | ||
| slots = list.slots() ; | ||
| expect( slots ).to.be.an( Array ) ; | ||
| expect( slots ).to.have.length( 3 ) ; | ||
| expect( slots.map( e => e.element ) ).to.equal( [ e1 , e2 , e3 ] ) ; | ||
| list = new List() ; | ||
| slots = list.slots() ; | ||
| expect( slots ).to.be.an( Array ) ; | ||
| expect( slots ).to.have.length( 0 ) ; | ||
| expect( slots.map( e => e.element ) ).to.equal( [] ) ; | ||
| list = new List( e1 , e2 , e2 , e2 , e3 ) ; | ||
| slots = list.slots() ; | ||
| expect( slots ).to.be.an( Array ) ; | ||
| expect( slots ).to.have.length( 5 ) ; | ||
| expect( slots.map( e => e.element ) ).to.equal( [ e1 , e2 , e2 , e2 , e3 ] ) ; | ||
| } ) ; | ||
| it( ".slotOf()/.lastSlotOf()" , () => { | ||
@@ -204,0 +231,0 @@ var list , |
45826
2.32%1160
3.02%