mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
fix list logic typ0
This commit is contained in:
parent
debdfee9c9
commit
22da36158c
@ -11,6 +11,7 @@ class Node {
|
||||
link (next) {
|
||||
this.next = next;
|
||||
next.prev = this;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,9 +31,8 @@ module.exports = class List extends EventEmitter {
|
||||
|
||||
add (obj) {
|
||||
const node = new Node(obj);
|
||||
if (this.tail) {
|
||||
this.tail.link(node);
|
||||
this.tail = node;
|
||||
if (this.start) {
|
||||
this.start = node.link(this.start);
|
||||
} else {
|
||||
this.start = node;
|
||||
this.tail = node;
|
||||
|
@ -51,10 +51,10 @@ test('list should be able remove until given value', (t) => {
|
||||
list.reverseRemoveUntilTrue(({ value }) => value === 4);
|
||||
t.true(list.toArray().length === 4);
|
||||
|
||||
list.reverseRemoveUntilTrue(({ value }) => value === 3);
|
||||
list.reverseRemoveUntilTrue(({ value }) => value === 5);
|
||||
t.true(list.toArray().length === 3);
|
||||
|
||||
list.reverseRemoveUntilTrue(({ value }) => value === 3);
|
||||
list.reverseRemoveUntilTrue(({ value }) => value === 5);
|
||||
t.true(list.toArray().length === 3);
|
||||
});
|
||||
|
||||
@ -98,7 +98,7 @@ test('should reverse iterate', (t) => {
|
||||
let iterateCount = 0;
|
||||
list.iterateReverse(({ value }) => {
|
||||
iterateCount++;
|
||||
if (value === 3) {
|
||||
if (value === 5) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -28,16 +28,13 @@ test.cb('should slice off list', (t) => {
|
||||
});
|
||||
|
||||
// console.time('4');
|
||||
list.add({ n: '4' }, moment().add(300, 'milliseconds'));
|
||||
|
||||
// console.time('3');
|
||||
list.add({ n: '3' }, moment().add(200, 'milliseconds'));
|
||||
|
||||
// console.time('2');
|
||||
list.add({ n: '2' }, moment().add(50, 'milliseconds'));
|
||||
|
||||
// console.time('1');
|
||||
list.add({ n: '1' }, moment().add(1, 'milliseconds'));
|
||||
list.add({ n: '2' }, moment().add(50, 'milliseconds'));
|
||||
list.add({ n: '3' }, moment().add(200, 'milliseconds'));
|
||||
list.add({ n: '4' }, moment().add(300, 'milliseconds'));
|
||||
|
||||
const expired = [];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user