How to use the uniq function from lodash

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

156
157
158
159
160
161
162
163
164
165
 * Turns requires into package names and filters out non-unique entries
 * @param {Array<string>} requires
 * @returns {Array<string>}
 */
const requiresToDeps = _.curry((requires) =>
  _.uniq(
    requires.map((d) => {
      // The following block makes sure the dep is a package name and not a file
      // reference. Given a require of `@scope/foo/bar/baz`, the following will
      // return `@scope/foo`. Given a require of `foo/bar/baz`, the folling will
fork icon305
star icon154
watch icon43

411
412
413
414
415
416
417
418
419
420
module.exports.unary               = _.unary;
module.exports.unescape            = _.unescape;
module.exports.union               = _.union;
module.exports.unionBy             = _.unionBy;
module.exports.unionWith           = _.unionWith;
module.exports.uniq                = _.uniq;
module.exports.uniqBy              = _.uniqBy;
module.exports.uniqWith            = _.uniqWith;
module.exports.uniqueId            = _.uniqueId;
module.exports.unset               = _.unset;
fork icon19
star icon122
watch icon0

+ 92 other calls in file

144
145
146
147
148
149
150
151
152
153
	topicsData.topics = await topics.getTopics(topicsTids, {
		uid: widget.uid,
		teaserPost: widget.data.teaserPost || 'first',
	});
} else if (fromGroups.length) {
	const uids = _.uniq(_.flatten(await groups.getMembersOfGroups(fromGroups)));
	const sets = uids.map((uid) => {
		if (filterCids.length) {
			return filterCids.map(cid => `cid:${cid}:uid:${uid}:tids`);
		}
fork icon21
star icon28
watch icon0

184
185
186
187
188
189
190
191
192
193

// write partials
fs.writeFileSync(path.join('./vendor/amazeui.hbs.partials.js'), partials);

// replace excluded style
includedStyleDep = _.uniq(includedStyleDep);
excludedStyleDep = _.uniq(excludedStyleDep);

var intersectionDep = _.intersection(includedStyleDep, excludedStyleDep);
excludedStyleDep = _.xor(excludedStyleDep, intersectionDep);
fork icon10
star icon26
watch icon5

+ 3 other calls in file

515
516
517
518
519
520
521
522
523
524
  groupsToFilter = [...(criteria.groups ? criteria.groups : [])];
  if (criteria.group) {
    groupsToFilter.push(criteria.group);
  }
}
groupsToFilter = _.uniq(groupsToFilter);

if (groupsToFilter.length === 0) {
  // User can't access any of the groups from the filters
  // We return an empty array as the result
fork icon45
star icon17
watch icon0

9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
*  to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Array} Returns a duplicate-value-free array.
* @example
*
* _.uniq([1, 2, 1, 3, 1]);
* // => [1, 2, 3]
*
* _.uniq([1, 1, 2, 2, 3], true);
* // => [1, 2, 3]
fork icon3
star icon2
watch icon1

+ 294 other calls in file

46
47
48
49
50
51
52
53
54
55
    done()
  })
})
it('unique', function (done) {
  getExercises(function (exercises) {
    var uniq = _.uniq(exercises)
    if (uniq.length !== exercises.length) {
      assert.fail('List contains duplicate exercise-names: ' + _.difference(exercises, uniq))
    }
    done()
fork icon1
star icon4
watch icon12

+ 5 other calls in file

159
160
161
162
163
164
165
166
167
168
169
170
171
console.log(unionBy); // => [2.1, 1.2]


const unionWith = _.unionWith([2.1], [1.2, 2.3], (a, b) => Math.floor(a) === Math.floor(b));
console.log(unionWith); // => [2.1, 1.2]


const uniq = _.uniq([2, 1, 2]);
console.log(uniq); // => [2, 1]


const uniqBy = _.uniqBy([2.1, 1.2, 2.3], Math.floor);
console.log(uniqBy); // => [2.1, 1.2]
fork icon0
star icon4
watch icon0

+ 15 other calls in file

78
79
80
81
82
83
84
85
86
87
88
  };
}


function getRoutePaths(route, path = null) {
  const defaultMethods = [].concat(route.methods || "get");
  const paths = _.uniq([path].concat(route.path, route.paths).filter(x => x)).map(x => {
    if (typeof x === "string") {
      return { [x]: defaultMethods };
    }
    return x;
fork icon309
star icon0
watch icon49

660
661
662
663
664
665
666
667
668
669
    const oneToTen = array.map((n) => n % 10)
    const nativeUniq = (xs) => Array.from(new Set(xs))
    return {
      iiris: () => A.from(S.from(oneToTen)),
      ramda: () => R.uniq(oneToTen),
      lodash: () => _.uniq(oneToTen),
      native: () => nativeUniq(oneToTen),
    }
  },
},
fork icon1
star icon31
watch icon0

+ 3 other calls in file

21
22
23
24
25
26
27
  isIncreasing: arr => arr.every((e, i) => i==0 || e >= arr[i-1]),
  isStrictlyIncreasing: arr => arr.every((e, i) => i==0 || e >= arr[i-1]),
  isDecreasing: arr => arr.every((e, i) => i==0 || e <= arr[i-1]),
  isStrictlyDecreasing: arr => arr.every((e, i) => i==0 || e <= arr[i-1]),
  increments: arr => arr.slice(1).map((e, i) => e - arr[i]),
  allDistinct: arr => _.uniq(arr).length === arr.length,
}
fork icon1
star icon4
watch icon0

+ 2 other calls in file

117
118
119
120
121
122
123
124
125
// Handle Environment
const environment = {LANDO_SERVICE_NAME: name, LANDO_SERVICE_TYPE: type};
// Handle http/https ports
const labels = {
  'io.lando.http-ports': _.uniq(['80', '443'].concat(moreHttpPorts)).join(','),
  'io.lando.https-ports': _.uniq(['443'].concat([sport])).join(','),
};
// Set a reasonable log size
const logging = {driver: 'json-file', options: {'max-file': '3', 'max-size': '10m'}};
fork icon0
star icon2
watch icon0

173
174
175
176
177
178
179
180
181
182
    this.serverless.cli.log(`=> ${problem}`);
  });
}

// (1) Generate dependency composition
const compositeModules = _.uniq(_.flatMap(stats.stats, compileStats => {
  const externalModules = _.concat(
    getExternalModules.call(this, compileStats),
    _.map(packageForceIncludes, whitelistedPackage => ({ external: whitelistedPackage }))
  );
fork icon409
star icon0
watch icon2

86
87
88
89
90
91
92
93
94
95
  }
})

walker.on('end', function (totalFile, totalFolder) {
  // 去重
  self.dependList = _.uniq(self.requireList)
  // 过滤掉系统模块
    .filter(function (i) {
      return sysList.indexOf(i) === -1
    })
fork icon34
star icon121
watch icon11

196
197
198
199
200
201
202
203
204
205
    }

    paths.push(lookup);
  });

  return _.uniq(paths.reverse());
};

/**
 * Get the global npm lookup directories
fork icon75
star icon0
watch icon1

+ 3 other calls in file

2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391


API.prototype.getWalletIdsFromOldCopay = function(username, password, blob) {
  var p = this._oldCopayDecrypt(username, password, blob);
  if (!p) return null;
  var ids = p.walletIds.concat(_.keys(p.focusedTimestamps));
  return _.uniq(ids);
};


API.PayPro = PayPro;

fork icon9
star icon0
watch icon0

109
110
111
112
113
114
115
116
117
118
    devFiles.forEach(function (devFile) {
        paths.push(devFile);
    });
});

paths = _.uniq(paths); // make sure there is no duplicate entries

var elems = [];

paths
fork icon3
star icon2
watch icon0

16
17
18
19
20
21
22
23
24
25
26
      result = result.concat(
        formatter(item.routes, item.path ? `${fixedParentPath}/${item.path}` : parentPath),
      );
    }
  });
  return uniq(result.filter((item) => !!item));
}


beforeEach(async () => {
  await page.goto(`${BASE_URL}`);
fork icon0
star icon4
watch icon0

535
536
537
538
539
540
541
542
543
544
  throw new Error(`Dialogflow CX API download current intents failed: ${err && err.message}`)
}

for (const newStruct of (utterances || [])) {
  const intent = newStruct.name
  const newUtterances = _.uniq(newStruct.utterances || [])
  const oldStruct = intents.find(i => i.displayName === intent)
  if (_.isNil(oldStruct)) {
    try {
      await client.createIntent({
fork icon1
star icon0
watch icon0

437
438
439
440
441
442
443
444
445
446
    let mergedMedia = injectedMedia;
    mergedMedia.push(...scheduledMedia);
    mergedMedia.forEach(mediaObj => {
        tagList.push(...mediaObj.Media.Tags)
    });
    options.tagsOR = _.uniq(tagList);
    //TODO: v1.4 Create different combos of block tags for tagsAND to give a more streamlined experience
}

let rightNow = moment().unix();
fork icon0
star icon2
watch icon1

+ 3 other calls in file

Other functions in lodash

Sorted by popularity

function icon

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