@@ -797,21 +797,18 @@ function createComparator (name, func) {
797
797
if ( args . length === 2 ) {
798
798
const a = runOptimizedOrFallback ( args [ 0 ] , engine , context , above )
799
799
const b = runOptimizedOrFallback ( args [ 1 ] , engine , context , above )
800
- if ( ! strict && typeof a !== typeof b ) {
801
- if ( typeof a === 'string' && Number . isNaN ( + a ) ) throw NaN
802
- if ( typeof b === 'string' && Number . isNaN ( + b ) ) throw NaN
803
- return func ( + a , + b )
804
- }
805
- return func ( a , b )
800
+ if ( strict || ( typeof a === 'string' && typeof b === 'string' ) ) return func ( a , b )
801
+ if ( Number . isNaN ( + precoerceNumber ( a ) ) ) throw NaN
802
+ if ( Number . isNaN ( + precoerceNumber ( b ) ) ) throw NaN
803
+ return func ( + a , + b )
806
804
}
807
805
let prev = runOptimizedOrFallback ( args [ 0 ] , engine , context , above )
808
806
for ( let i = 1 ; i < args . length ; i ++ ) {
809
807
const current = runOptimizedOrFallback ( args [ i ] , engine , context , above )
810
- if ( ! strict && typeof current !== typeof prev ) {
811
- if ( typeof current === 'string' && Number . isNaN ( + current ) ) throw NaN
812
- if ( i === 1 && typeof prev === 'string' && Number . isNaN ( + prev ) ) throw NaN
813
- if ( ! func ( + prev , + current ) ) return false
814
- } else if ( ! func ( prev , current ) ) return false
808
+ if ( strict || ( typeof current === 'string' && typeof prev === 'string' ) ) if ( ! func ( prev , current ) ) return false
809
+ if ( Number . isNaN ( + precoerceNumber ( current ) ) ) throw NaN
810
+ if ( i === 1 && Number . isNaN ( + precoerceNumber ( prev ) ) ) throw NaN
811
+ if ( ! func ( + prev , + current ) ) return false
815
812
prev = current
816
813
}
817
814
return true
@@ -821,21 +818,18 @@ function createComparator (name, func) {
821
818
if ( args . length === 2 ) {
822
819
const a = await runOptimizedOrFallback ( args [ 0 ] , engine , context , above )
823
820
const b = await runOptimizedOrFallback ( args [ 1 ] , engine , context , above )
824
- if ( ! strict && typeof a !== typeof b ) {
825
- if ( typeof a === 'string' && Number . isNaN ( + a ) ) throw NaN
826
- if ( typeof b === 'string' && Number . isNaN ( + b ) ) throw NaN
827
- return func ( + a , + b )
828
- }
829
- return func ( a , b )
821
+ if ( strict || ( typeof a === 'string' && typeof b === 'string' ) ) return func ( a , b )
822
+ if ( Number . isNaN ( + precoerceNumber ( a ) ) ) throw NaN
823
+ if ( Number . isNaN ( + precoerceNumber ( b ) ) ) throw NaN
824
+ return func ( + a , + b )
830
825
}
831
826
let prev = await runOptimizedOrFallback ( args [ 0 ] , engine , context , above )
832
827
for ( let i = 1 ; i < args . length ; i ++ ) {
833
828
const current = await runOptimizedOrFallback ( args [ i ] , engine , context , above )
834
- if ( ! strict && typeof current !== typeof prev ) {
835
- if ( typeof current === 'string' && Number . isNaN ( + current ) ) throw NaN
836
- if ( i === 1 && typeof prev === 'string' && Number . isNaN ( + prev ) ) throw NaN
837
- if ( ! func ( + prev , + current ) ) return false
838
- } else if ( ! func ( prev , current ) ) return false
829
+ if ( strict || ( typeof current === 'string' && typeof prev === 'string' ) ) if ( ! func ( prev , current ) ) return false
830
+ if ( Number . isNaN ( + precoerceNumber ( current ) ) ) throw NaN
831
+ if ( i === 1 && Number . isNaN ( + precoerceNumber ( prev ) ) ) throw NaN
832
+ if ( ! func ( + prev , + current ) ) return false
839
833
prev = current
840
834
}
841
835
return true
0 commit comments