Get Compare From Less Comparator - Node.js Math

Node.js examples for Math:Compare

Description

Get Compare From Less Comparator

Demo Code


function numberLessComparator ( a, b )
{
  return a < b;
}

function numberCmpComparator ( a, b )
{
  return a - b;/*  w w w .j  a va2  s  .co  m*/
}

function getCmpFromLessComparator ( lessComparator )
{
  return function ( a, b )
  {
    if ( lessComparator( a, b ) )
      return -1;
    if ( lessComparator( b, a ) )
      return 1;
    return 0;
  };
}

function getLessFromCmpComparator ( cmpComparator )
{
  return function ( a, b )
  {
    return cmpComparator( a, b ) < 0;
  };
}

Related Tutorials