FCF 2.0 development in progress...
> > > >
[News] [Packages API] [Downloads] [Donate to the project] [Contacts]

fcf.compare() function

integer fcf.compare(mixed a_left, mixed a_right, boolean a_strict = false)

Package: fcf-framework-core

File: fcf-framework-core:fcf.js

Available from version: 2.0.2

Compares two values.

The objects being compared can be simple types, arrays, objects, Date, Map and Set

When comparing two NaN, the function will return 0

Arguments

mixed a_left
- The first value to compare.

mixed a_right
- The second value to compare.

boolean a_strict = false
- If it is true, then a strict comparison is used for comparison === simple types, and for objects, a check for the equality of designers is still performed.

If it is false, then comparison == is performed for simple types, and for objects comparing their contents.

Result
integer
- Returns 0 if two values are equal;

Returns 1 if a_left > a_right;

Returns -1 if a_left < a_right;

When comparing two NaN, the function will return 0

Example: Function application

{ let result = fcf.compare({value: 2}, {value: 1}); console.log(`{value: 2} cmp {value: 1}: `, result); } { let result = fcf.compare({value: 1}, {value: 1}); console.log(`{value: 1} cmp {value: 1}: `, result); } { let result = fcf.compare({value: 1}, {value: 2}); console.log(`{value: 1} cmp {value: 2}: `, result); } { let result = fcf.compare({value: "1"}, {value: 1}); console.log(`{value: "1"} cmp {value: 1}: `, result); } { let result = fcf.compare({value: "1"}, {value: 1}, true); console.log(`{value: "1"} strict_cmp {value: 1}:`, result); }

Output:

{value: 2} cmp {value: 1}: 1 {value: 1} cmp {value: 1}: 0 {value: 1} cmp {value: 2}: -1 {value: "1"} cmp {value: 1}: 0 {value: "1"} strict_cmp {value: 1}: 1