Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function compare(v, w) {
if (v === w) {
return 0;
}
var type1 = typeOf(v);
var type2 = typeOf(w);
if (Comparable) {
if (type1 === 'instance' && Comparable.detect(v) && v.constructor.compare) {
return v.constructor.compare(v, w);
}
if (type2 === 'instance' && Comparable.detect(w) && w.constructor.compare) {
return w.constructor.compare(w, v) * -1;
}
}
var res = spaceship(TYPE_ORDER[type1], TYPE_ORDER[type2]);
if (res !== 0) {
return res;
}
// types are equal - so we have to check values now
switch (type1) {
var wLen = w.length;
var len = Math.min(vLen, wLen);
for (var i = 0; i < len; i++) {
var r = compare(v[i], w[i]);
if (r !== 0) {
return r;
}
}
// all elements are equal now
// shorter array should be ordered first
return spaceship(vLen, wLen);
case 'instance':
if (Comparable && Comparable.detect(v)) {
return v.compare(v, w);
}
return 0;
case 'date':
return spaceship(v.getTime(), w.getTime());
default:
return 0;
}
}
export default function compare(v, w) {
if (v === w) {
return 0;
}
var type1 = typeOf(v);
var type2 = typeOf(w);
if (Comparable) {
if (type1 === 'instance' && Comparable.detect(v) && v.constructor.compare) {
return v.constructor.compare(v, w);
}
if (type2 === 'instance' && Comparable.detect(w) && w.constructor.compare) {
return w.constructor.compare(w, v) * -1;
}
}
var res = spaceship(TYPE_ORDER[type1], TYPE_ORDER[type2]);
if (res !== 0) {
return res;
}
// types are equal - so we have to check values now
switch (type1) {
case 'boolean':
case 'number':
return spaceship(v, w);