How to use the min function from lodash

Find comprehensive JavaScript lodash.min code examples handpicked from public code repositorys.

lodash.min is a function that returns the smallest element in an array or object.

94
95
96
97
98
99
100
101
102
103
  // aggregate all stats
  this.stats = {
    albums: this.albums.length,
    photos: _.sum(_.compact(_.concat(nestedPhotos, currentPhotos))) || 0,
    videos: _.sum(_.compact(_.concat(nestedVideos, currentVideos))) || 0,
    fromDate: _.min(_.compact(_.concat(nestedFromDates, currentFromDate))),
    toDate: _.max(_.compact(_.concat(nestedToDates, currentToDate)))
  }
  this.stats.total = this.stats.photos + this.stats.videos
}
fork icon80
star icon649
watch icon21

+ 4 other calls in file

4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
* var characters = [
*   { 'name': 'barney', 'age': 36 },
*   { 'name': 'fred',   'age': 40 }
* ];
*
* _.min(characters, function(chr) { return chr.age; });
* // => { 'name': 'barney', 'age': 36 };
*
* // using "_.pluck" callback shorthand
* _.min(characters, 'age');
fork icon73
star icon711
watch icon29

+ 5 other calls in file

How does lodash.min work?

lodash.min is a method provided by the Lodash library which returns the smallest element in a given array or collection of values, or NaN if the input is empty or contains non-comparable elements. It does this by first checking if the input is an array or a collection, and then using the Math.min function to find the minimum value. It also supports an optional iteratee function, which can be used to transform or map the values before finding the minimum.

104
105
106
107
108
109
110
111
112
113

  for (let pair of _.pairs(sources[SOURCEMAP_KEY])) {
    let hashPath = pair[0];
    let paths = pair[1];

    depths[hashPath] = _.min(_.map(
      paths, (p) => p.split('/').length));
  }
}
return depths;
fork icon65
star icon1
watch icon3

263
264
265
266
267
268
269
270
271
272
module.exports.merge               = _.merge;
module.exports.mergeWith           = _.mergeWith;
module.exports.method              = _.method;
module.exports.methodOf            = _.methodOf;
module.exports.methodize           = _.methodize;
module.exports.min                 = _.min;
module.exports.minBy               = _.minBy;
module.exports.mixin               = _.mixin;
module.exports.mod                 = _.mod;
module.exports.mul                 = _.mul;
fork icon19
star icon122
watch icon0

+ 92 other calls in file

Ai Example

1
2
3
4
5
6
const _ = require("lodash");

const numbers = [3, 7, 1, 8, 4, 2, 9];
const smallestNumber = _.min(numbers);

console.log(smallestNumber); // Output: 1

In this example, lodash.min is used to find the smallest number in an array of numbers. The function takes an array as its argument and returns the smallest number in the array. In this case, it returns the value of 1.

257
258
259
260
261
262
263
264
265
266
  params: [num1, num10, num100, num1000],
  benchmarks: (array) => {
    const min = (a, b) => (a < b ? a : b)
    return {
      iiris: () => A.minimum(array),
      lodash: () => _.min(array),
      native: () => array.reduce(min),
    }
  },
},
fork icon1
star icon31
watch icon0

242
243
244
245
246
247
248
249
250
251
const grades = this.points.map(p => p.grade)
const terrains = this.terrainFactors.map(tf => (tf.tF / 100 + 1))
const stats = {
  altitude: {
    max: _.max(alts),
    min: _.min(alts)
  },
  grade: {
    max: _.max(grades),
    min: _.min(grades)
fork icon3
star icon8
watch icon3

+ 8 other calls in file

557
558
559
560
561
562
563
564
565
566
567
568
569
console.log(mean); // => 5


const meanBy = _.meanBy([{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }], o => o.n);
console.log(meanBy); // => 5


const min = _.min([4, 2, 8, 6]);
console.log(min); // => 2


const minBy = _.minBy([{ 'n': 1 }, { 'n': 2 }], o => o.n);
console.log(minBy); // => { 'n': 1 }
fork icon0
star icon4
watch icon0

+ 15 other calls in file

644
645
646
647
648
649
650
651
652
653
 */
histogram(data, bins = 10) {
    if (bins === 1) {
        return [data.length];
    }
    const bin_width = (_.max(data) - _.min(data)) / (bins - 1);
    let min = Infinity;
    let max = -Infinity;

    for (const item of data) {
fork icon0
star icon0
watch icon1

+ 4 other calls in file

887
888
889
890
891
892
893
894
895
896
/**
 * Returns the minimum degree in this graph.
 * @returns {number}
 */
get minDegree() {
    return _.min(_.values(this.getDegrees()));
}

/**
 * Returns an array representing the histogram of degrees.
fork icon0
star icon0
watch icon2

260
261
262
263
264
265
266
267
268
269

const existing = _.find(newUsers, u => u.contributorId === _.trim(puData.contributorUsername));

if(existing){
    console.log(`Duplicate detected for id "${_.trim(puData.contributorUsername)}":`, existing, puData);
    existing.firstContributedAt = _.min([existing.firstContributedAt, puData.firstDataEnteredAt]);
    continue
}

const newUser = {
fork icon0
star icon0
watch icon2

78
79
80
81
82
83
84
85
86
87
 *     request property for the request value.
 */
function listFeatures(call) {
  var lo = call.request.getLo();
  var hi = call.request.getHi();
  var left = _.min([lo.getLongitude(), hi.getLongitude()]);
  var right = _.max([lo.getLongitude(), hi.getLongitude()]);
  var top = _.max([lo.getLatitude(), hi.getLatitude()]);
  var bottom = _.min([lo.getLatitude(), hi.getLatitude()]);
  // For each feature, check if it is in the given bounding box
fork icon0
star icon0
watch icon0

88
89
90
91
92
93
94
95
96
97
 *     request property for the request value.
 */
function listFeatures(call) {
  var lo = call.request.lo;
  var hi = call.request.hi;
  var left = _.min([lo.longitude, hi.longitude]);
  var right = _.max([lo.longitude, hi.longitude]);
  var top = _.max([lo.latitude, hi.latitude]);
  var bottom = _.min([lo.latitude, hi.latitude]);
  // For each feature, check if it is in the given bounding box
fork icon0
star icon0
watch icon0

156
157
158
159
160
161
162
163
164
165
get medianScore() {
    return this.requests.map(r => r.score).sort()[parseInt(this.requests.length / 2)]
}

get minScore() {
    return _.min(this.requests.map(r => r.score))
}

get maxScore() {
    return _.max(this.requests.map(r => r.score))
fork icon0
star icon0
watch icon0

+ 3 other calls in file

113
114
115
116
117
118
119
120
121
122

var slope = numerator / denominator;
var intercept = yBar - slope * xBar;

return {
    minX: _.min(x),
    maxX: _.max(x),
    slope: slope,
    intercept: intercept
};
fork icon0
star icon0
watch icon23

+ 15 other calls in file

3072
3073
3074
3075
3076
3077
3078
3079
3080
function(next) {
  getNormalizedTxs(addresses, from, to, next);
},
function(txs, next) {
  // Fetch all proposals in [t - 7 days, t + 1 day]
  var minTs = _.min(txs.items, 'time').time - 7 * 24 * 3600;
  var maxTs = _.max(txs.items, 'time').time + 1 * 24 * 3600;

  async.parallel([
fork icon0
star icon0
watch icon0

Other functions in lodash

Sorted by popularity

function icon

lodash.get is the most popular function in lodash (7670 examples)