minor tweaking...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-11-16 05:18:55 +03:00
parent 4ddb927934
commit 711933113e
3 changed files with 18 additions and 11 deletions

View File

@ -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 }) }

View File

@ -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": {

View File

@ -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...
//