Checks if value is less than other using JavaScript's native comparison operator
npx @tessl/cli install tessl/npm-lodash-lt@3.9.0Lodash.lt provides a simple utility function for performing less-than comparison operations. This function is part of the Lodash library's Lang category and offers a functional programming approach to comparison operations, allowing for consistent API usage and potential composition with other Lodash utilities.
npm install lodash (full library) or npm install lodash.lt (individual function)From full lodash library:
const _ = require('lodash');ES6 imports (if using a module system):
import _ from 'lodash';From individual lodash.lt package:
const lt = require('lodash.lt');For direct access from full library:
const _ = require('lodash');
const lt = _.lt;Using full lodash library:
const _ = require('lodash');
// Compare numbers
console.log(_.lt(1, 3)); // => true
console.log(_.lt(3, 3)); // => false
console.log(_.lt(3, 1)); // => false
// Compare strings
console.log(_.lt('abc', 'def')); // => true
console.log(_.lt('def', 'abc')); // => falseUsing individual lodash.lt package:
const lt = require('lodash.lt');
// Compare numbers
console.log(lt(1, 3)); // => true
console.log(lt(3, 3)); // => false
console.log(lt(3, 1)); // => false
// Compare mixed types (uses JavaScript's native < operator behavior)
console.log(lt(1, '2')); // => true
console.log(lt('10', 5)); // => falseChecks if the first value is less than the second value using JavaScript's native less-than operator.
/**
* Checks if `value` is less than `other`.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @returns {boolean} Returns `true` if `value` is less than `other`, else `false`.
*/
function lt(value, other);Parameters:
value (*): The value to compare - can be any JavaScript valueother (*): The other value to compare - can be any JavaScript valueReturns:
boolean: Returns true if value is less than other, else falseBehavior:
< operator for comparisonUsage Examples:
const _ = require('lodash');
// Numeric comparisons
_.lt(1, 3); // => true
_.lt(3, 3); // => false
_.lt(3, 1); // => false
// String comparisons (lexicographic)
_.lt('abc', 'def'); // => true
_.lt('def', 'abc'); // => false
_.lt('abc', 'abc'); // => false
// Mixed type comparisons (follows JavaScript < operator rules)
_.lt(1, '2'); // => true (1 < 2)
_.lt('10', 5); // => false ('10' converted to 10, 10 < 5 is false)
// Can be used in functional programming contexts
const numbers = [3, 1, 4, 1, 5];
const lessThanThree = numbers.filter(n => _.lt(n, 3));
console.log(lessThanThree); // => [1, 1]
// Useful for sorting predicates or custom comparison logic
const compareWithTwo = (value) => _.lt(value, 2);
console.log(compareWithTwo(1)); // => true
console.log(compareWithTwo(3)); // => false