Checks if value is less than other using JavaScript's native comparison operator
npx @tessl/cli install tessl/npm-lodash--lt@3.9.00
# Lodash.lt
1
2
Lodash.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.
3
4
## Package Information
5
6
- **Package Name**: lodash.lt (part of lodash library)
7
- **Package Type**: npm
8
- **Language**: JavaScript
9
- **Installation**: `npm install lodash` (full library) or `npm install lodash.lt` (individual function)
10
11
## Core Imports
12
13
From full lodash library:
14
15
```javascript
16
const _ = require('lodash');
17
```
18
19
ES6 imports (if using a module system):
20
21
```javascript
22
import _ from 'lodash';
23
```
24
25
From individual lodash.lt package:
26
27
```javascript
28
const lt = require('lodash.lt');
29
```
30
31
For direct access from full library:
32
33
```javascript
34
const _ = require('lodash');
35
const lt = _.lt;
36
```
37
38
## Basic Usage
39
40
Using full lodash library:
41
42
```javascript
43
const _ = require('lodash');
44
45
// Compare numbers
46
console.log(_.lt(1, 3)); // => true
47
console.log(_.lt(3, 3)); // => false
48
console.log(_.lt(3, 1)); // => false
49
50
// Compare strings
51
console.log(_.lt('abc', 'def')); // => true
52
console.log(_.lt('def', 'abc')); // => false
53
```
54
55
Using individual lodash.lt package:
56
57
```javascript
58
const lt = require('lodash.lt');
59
60
// Compare numbers
61
console.log(lt(1, 3)); // => true
62
console.log(lt(3, 3)); // => false
63
console.log(lt(3, 1)); // => false
64
65
// Compare mixed types (uses JavaScript's native < operator behavior)
66
console.log(lt(1, '2')); // => true
67
console.log(lt('10', 5)); // => false
68
```
69
70
## Capabilities
71
72
### Less Than Comparison
73
74
Checks if the first value is less than the second value using JavaScript's native less-than operator.
75
76
```javascript { .api }
77
/**
78
* Checks if `value` is less than `other`.
79
*
80
* @static
81
* @memberOf _
82
* @category Lang
83
* @param {*} value The value to compare.
84
* @param {*} other The other value to compare.
85
* @returns {boolean} Returns `true` if `value` is less than `other`, else `false`.
86
*/
87
function lt(value, other);
88
```
89
90
**Parameters:**
91
- `value` (*): The value to compare - can be any JavaScript value
92
- `other` (*): The other value to compare - can be any JavaScript value
93
94
**Returns:**
95
- `boolean`: Returns `true` if `value` is less than `other`, else `false`
96
97
**Behavior:**
98
- Uses JavaScript's native `<` operator for comparison
99
- Follows JavaScript's type coercion rules when comparing different types
100
- Works with numbers, strings, and other comparable JavaScript values
101
- Part of Lodash's functional programming approach to utility operations
102
103
**Usage Examples:**
104
105
```javascript
106
const _ = require('lodash');
107
108
// Numeric comparisons
109
_.lt(1, 3); // => true
110
_.lt(3, 3); // => false
111
_.lt(3, 1); // => false
112
113
// String comparisons (lexicographic)
114
_.lt('abc', 'def'); // => true
115
_.lt('def', 'abc'); // => false
116
_.lt('abc', 'abc'); // => false
117
118
// Mixed type comparisons (follows JavaScript < operator rules)
119
_.lt(1, '2'); // => true (1 < 2)
120
_.lt('10', 5); // => false ('10' converted to 10, 10 < 5 is false)
121
122
// Can be used in functional programming contexts
123
const numbers = [3, 1, 4, 1, 5];
124
const lessThanThree = numbers.filter(n => _.lt(n, 3));
125
console.log(lessThanThree); // => [1, 1]
126
127
// Useful for sorting predicates or custom comparison logic
128
const compareWithTwo = (value) => _.lt(value, 2);
129
console.log(compareWithTwo(1)); // => true
130
console.log(compareWithTwo(3)); // => false
131
```