diff options
author | Alexander Early <alexander.early@gmail.com> | 2017-04-08 18:24:59 -0700 |
---|---|---|
committer | Alexander Early <alexander.early@gmail.com> | 2017-04-08 18:24:59 -0700 |
commit | 07402822c3125a019c3060104eb7da54e0ccc5b6 (patch) | |
tree | 4bcafa8866fa42c0de1d3a895bd107d488d11fed | |
parent | 291c81138258cd22be3a9bc9b2f1990eacaba634 (diff) | |
download | async-07402822c3125a019c3060104eb7da54e0ccc5b6.tar.gz |
rename filter to remove
-rw-r--r-- | lib/internal/DoublyLinkedList.js | 4 | ||||
-rw-r--r-- | lib/internal/queue.js | 4 | ||||
-rw-r--r-- | mocha_test/linked_list.js | 24 |
3 files changed, 15 insertions, 17 deletions
diff --git a/lib/internal/DoublyLinkedList.js b/lib/internal/DoublyLinkedList.js index 0feea1b..0e3b394 100644 --- a/lib/internal/DoublyLinkedList.js +++ b/lib/internal/DoublyLinkedList.js @@ -75,11 +75,11 @@ DLL.prototype.toArray = function () { return arr; } -DLL.prototype.filter = function (testFn) { +DLL.prototype.remove = function (testFn) { var curr = this.head; while(!!curr) { var next = curr.next; - if (!testFn(curr)) { + if (testFn(curr)) { this.removeLink(curr); } curr = next; diff --git a/lib/internal/queue.js b/lib/internal/queue.js index 87d49f4..f058568 100644 --- a/lib/internal/queue.js +++ b/lib/internal/queue.js @@ -103,9 +103,7 @@ export default function queue(worker, concurrency, payload) { _insert(data, true, callback); }, remove: function (testFn) { - q._tasks = q._tasks.filter(function (node) { - return !testFn(node); - }) + q._tasks.remove(testFn); }, process: function () { // Avoid trying to start too many processing operations. This can occur diff --git a/mocha_test/linked_list.js b/mocha_test/linked_list.js index 19cb155..ab4b223 100644 --- a/mocha_test/linked_list.js +++ b/mocha_test/linked_list.js @@ -12,57 +12,57 @@ describe('DoublyLinkedList', function () { expect(list.toArray()).to.eql([0, 1, 2, 3, 4]); }); - it('filter', function() { + it('remove', function() { var list = new DLL(); for (var i = 0; i < 5; i++) { list.push({data: i}); } - list.filter(function (node) { - return node.data !== 3; + list.remove(function (node) { + return node.data === 3; }) expect(list.toArray()).to.eql([0, 1, 2, 4]); }); - it('filter (head)', function() { + it('remove (head)', function() { var list = new DLL(); for (var i = 0; i < 5; i++) { list.push({data: i}); } - list.filter(function (node) { - return node.data !== 0; + list.remove(function (node) { + return node.data === 0; }) expect(list.toArray()).to.eql([1, 2, 3, 4]); }); - it('filter (tail)', function() { + it('remove (tail)', function() { var list = new DLL(); for (var i = 0; i < 5; i++) { list.push({data: i}); } - list.filter(function (node) { - return node.data !== 4; + list.remove(function (node) { + return node.data === 4; }) expect(list.toArray()).to.eql([0, 1, 2, 3]); }); - it('filter (all)', function() { + it('remove (all)', function() { var list = new DLL(); for (var i = 0; i < 5; i++) { list.push({data: i}); } - list.filter(function (node) { - return node.data > 5; + list.remove(function (node) { + return node.data < 5; }) expect(list.toArray()).to.eql([]); |