From 711933113e15853beae0e8bbbe7c04f2a7c10bfd Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 16 Nov 2020 05:18:55 +0300 Subject: [PATCH] minor tweaking... Signed-off-by: Alex A. Naanou --- Array.js | 21 ++++++++++++++++----- package.json | 2 +- runner.js | 6 +----- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Array.js b/Array.js index 1ce7242..ffe26df 100644 --- a/Array.js +++ b/Array.js @@ -99,7 +99,7 @@ Array.prototype.compact = function(){ }) -// Return an array with duplicate elements removed... +// Return a new array with duplicate elements removed... // // NOTE: order is preserved... Array.prototype.unique = function(normalize){ @@ -143,6 +143,15 @@ Array.prototype.setCmp = function(other){ // Sort as the other array... // +// Sort as array placing the sorted items at head... +// .sortAs(array) +// .sortAs(array, 'head') +// -> sorted +// +// Sort as array placing the sorted items at tail... +// .sortAs(array, 'tail') +// -> sorted +// // This will sort the intersecting items in the head keeping the rest // of the items in the same relative order... // @@ -150,8 +159,10 @@ Array.prototype.setCmp = function(other){ // is used... // // XXX should this extend/patch .sort(..)??? -// ...currently do not see a clean way to do this... -Array.prototype.sortAs = function(other){ +// ...currently do not see a clean way to do this without extending +// and replacing Array or directly re-wrapping .sort(..)... +Array.prototype.sortAs = function(other, place='head'){ + place = place == 'tail' ? -1 : 1 // NOTE: the memory overhead here is better than the time overhead // when using .indexOf(..)... other = other.toMap() @@ -162,9 +173,9 @@ Array.prototype.sortAs = function(other){ return i == null && j == null ? orig.get(a) - orig.get(b) : i == null ? - 1 + place : j == null ? - -1 + -place : i - j }) } diff --git a/package.json b/package.json index 35414b4..d7b456d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-types", - "version": "3.7.3", + "version": "3.7.5", "description": "Generic JavaScript types and type extensions...", "main": "main.js", "scripts": { diff --git a/runner.js b/runner.js index 036310b..790b010 100644 --- a/runner.js +++ b/runner.js @@ -93,11 +93,7 @@ module.Queue = object.Constructor('Queue', Array, { return this.sortAs(tasks) }, // XXX same as prioritize but adds stuff to the tail... delay: function(...tasks){ - this.splice(0, this.length, - ...this.slice() - .reverse() - .sortAs(tasks.reverse())) - return this }, + return this.sortAs(tasks, true) }, // main runner... //