array-order
Advanced tools
Comparing version 0.9.1 to 1.0.0
export {default as sort} from './sort.js' | ||
export {default as rank} from './rank.js' | ||
export {default as pick} from './pick.js' | ||
export {default as heap} from './heap.js' | ||
export {default as swap} from './swap.js' | ||
export {default as shift} from './shift.js' |
{ | ||
"name": "array-order", | ||
"version": "0.9.1", | ||
"version": "1.0.0", | ||
"type": "module", | ||
@@ -19,3 +19,3 @@ "main": "./index.js", | ||
"scripts": { | ||
"test": "node ./tst/heap && node ./tst/rank && node ./tst/sort" | ||
"test": "node ./tst/heap && node ./tst/pick && node ./tst/sort" | ||
}, | ||
@@ -22,0 +22,0 @@ "repository": { |
22
rank.js
@@ -1,13 +0,11 @@ | ||
export default function(seq, arr) { | ||
var len = seq.length | ||
for (var i=0; i<len; ++i) { | ||
var j = seq[i] | ||
while (j<i) j = seq[j] | ||
if (i!==j) { | ||
var t = arr[i] | ||
arr[i] = arr[j] | ||
arr[j] = t | ||
} | ||
} | ||
return arr | ||
export default function(ref, dir) { | ||
var seq = [], | ||
i = 0 | ||
while (i<ref.length) seq[i] = i++ | ||
seq.sort( | ||
dir < 0 ? function(a,b) { return ref[b]-ref[a] } | ||
: typeof dir === 'function' ? function(a,b) { return dir(ref[a], ref[b]) } | ||
: function(a,b) { return ref[a]-ref[b] } | ||
) | ||
return seq | ||
} |
@@ -11,3 +11,4 @@ <!-- markdownlint-disable MD004 MD007 MD010 MD012 MD041 MD022 MD024 MD032 MD036 --> | ||
* **sort** creates a sorter to sort multiple columns `(ref:Array [,compare]) => (a:Array) => a` | ||
* **rank** performs reordering based on given ranks `(ranks:Array, a:Array) => a:Array` | ||
* **rank** creates the sorting sequence an array `(a:Array, [,compare]) => rank:Array` | ||
* **pick** performs reordering based on given ranks `(rank:Array, a:Array) => a:Array` | ||
* **heap** creates a function that performs permutation, each one different `a:Array => () => a` | ||
@@ -14,0 +15,0 @@ |
11
sort.js
import rank from './rank.js' | ||
import pick from './pick.js' | ||
export default function(ref, dir) { | ||
var seq = [], | ||
i = 0 | ||
while (i<ref.length) seq[i] = i++ | ||
seq.sort( | ||
dir < 0 ? function(a,b) { return ref[b]-ref[a] } | ||
: typeof dir === 'function' ? function(a,b) { return dir(ref[a], ref[b]) } | ||
: function(a,b) { return ref[a]-ref[b] } | ||
) | ||
return rank.bind(null,seq) | ||
return pick.bind(null,rank(ref, dir)) | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
7588
18
183
1
44