MCPcopy Create free account
hub / github.com/EricSimons/ionic-course / compare

Function compare

code/songhop/www/lib/angular/angular.js:17574–17608  ·  view source on GitHub ↗
(v1, v2)

Source from the content-addressed store, hash-verified

17572 : comp;
17573 }
17574 function compare(v1, v2) {
17575 var t1 = typeof v1;
17576 var t2 = typeof v2;
17577 // Prepare values for Abstract Relational Comparison
17578 // (http://www.ecma-international.org/ecma-262/5.1/#sec-11.8.5):
17579 // If the resulting values are identical, return 0 to prevent
17580 // incorrect re-ordering.
17581 if (t1 === t2 && t1 === "object") {
17582 // If types are both numbers, emulate abstract ToPrimitive() operation
17583 // in order to get primitive values suitable for comparison
17584 t1 = typeof (v1.valueOf ? v1 = v1.valueOf() : v1);
17585 t2 = typeof (v2.valueOf ? v2 = v2.valueOf() : v2);
17586 if (t1 === t2 && t1 === "object") {
17587 // Object.prototype.valueOf will return the original object, by
17588 // default. If we do not receive a primitive value, use ToString()
17589 // instead.
17590 t1 = typeof (v1.toString ? v1 = v1.toString() : v1);
17591 t2 = typeof (v2.toString ? v2 = v2.toString() : v2);
17592
17593 // If the end result of toString() for each item is the same, do not
17594 // perform relational comparison, and do not re-order objects.
17595 if (t1 === t2 && v1 === v2 || t1 === "object") return 0;
17596 }
17597 }
17598 if (t1 === t2) {
17599 if (t1 === "string") {
17600 v1 = v1.toLowerCase();
17601 v2 = v2.toLowerCase();
17602 }
17603 if (v1 === v2) return 0;
17604 return v1 < v2 ? -1 : 1;
17605 } else {
17606 return t1 < t2 ? -1 : 1;
17607 }
17608 }
17609 };
17610}
17611

Callers 2

parentValueWatchFunction · 0.70
orderByFilterFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected