Function

compare (v, w) Number public

Module: @ember/utils
import { compare } from '@ember/utils';
v
Object
First value to compare
w
Object
Second value to compare
returns
Number
-1 if v < w, 0 if v = w and 1 if v > w.

Compares two javascript values and returns:

  • -1 if the first is smaller than the second,

  • 0 if both are equal,

  • 1 if the first is greater than the second.

    import { compare } from '@ember/utils';
    
    compare('hello', 'hello');  // 0
    compare('abc', 'dfg');      // -1
    compare(2, 1);              // 1

If the types of the two objects are different precedence occurs in the following order, with types earlier in the list considered < types later in the list:

  • undefined

  • null

  • boolean

  • number

  • string

  • array

  • object

  • instance

  • function

  • class

  • date

    import { compare } from '@ember/utils';
    
    compare('hello', 50);       // 1
    compare(50, 'hello');       // -1

© 2020 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://api.emberjs.com/ember/3.25/functions/@ember%2Futils/compare