fcf.compare() function
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,
When comparing two
Arguments
- The first value to compare.
- The second value to compare.
- 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
Result
- Returns 0 if two values are equal;
Returns 1 if a_left > a_right;
Returns -1 if a_left < a_right;
When comparing two
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