How to use the uniqWith function from lodash

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

470
471
472
473
474
475
476
477
478
479
const nonLinkLocal = item.ip6_subnets
  .filter(_.isString)
  .map(n => new Address6(n))
  .filter(a => !a.isLinkLocal())
// multiple IPs in same subnet might be assigned
this.sysinfo[r].subnetAddress6 = _.uniqWith(nonLinkLocal, (a,b) =>
  a.startAddress().canonicalForm() == b.startAddress().canonicalForm() && a.subnetMask == b.subnetMask
)
for (const subnet6 of this.sysinfo[r].subnetAddress6) {
  cidr6Trie.add(`${subnet6.correctForm()}/${subnet6.subnetMask}`, r);
fork icon117
star icon456
watch icon48

+ 7 other calls in file

413
414
415
416
417
418
419
420
421
422
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;
module.exports.unsplat             = _.unsplat;
module.exports.unsplatl            = _.unsplatl;
fork icon19
star icon122
watch icon0

+ 92 other calls in file

165
166
167
168
169
170
171
172
173
174
175
176
177
console.log(uniq); // => [2, 1]


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


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


const unzip = _.unzip([['a', 1, true], ['b', 2, false]]);
console.log(unzip); // => [['a', 'b'], [1, 2], [true, false]]
fork icon0
star icon4
watch icon0

+ 15 other calls in file

315
316
317
318
319
320
321
322
323
324
const researchersOrganisationAgents = await this.getOrCreateAgents(
  "organisation",
  researchersOrganisations
);

const funderNames = _.uniqWith(
  projects
    .flatMap((project) => project.funder)
    .filter((name) => name.length > 0)
    .map((name) => ({ name: name })),
fork icon0
star icon0
watch icon5

+ 54 other calls in file

142
143
144
145
146
147
148
149
150
151
  }
  return principles;
};
// levelsDisplay() {
//   return _.reverse(
//     _.uniqWith(
//       this.levels.map((l) => {
//         return { name: l.attributes.name, code: l.attributes.code };
//       }),
//       _.isEqual
fork icon0
star icon0
watch icon2

+ 119 other calls in file

399
400
401
402
403
404
405
406
407

if (makeUnique) {
  //make the elements of that array unique
  propsToAggregate.forEach(function (prop) {
    let itemArray = _.get(uniqueObjects[key], prop);
    itemArray = _.uniqWith(itemArray, _.isEqual);
    _.set(uniqueObjects[key], prop, itemArray);
  });
}
fork icon0
star icon0
watch icon3

+ 51 other calls in file

189
190
191
192
193
194
195
196
197
198
199
200
        })
      }
    }
  }


  errorList = uniqWith(errorList, isEqual)


  return errorList
}

fork icon0
star icon0
watch icon1

+ 2 other calls in file

462
463
464
465
466
467
468
469
470
471
  });

  return acc;
}, []);

const models = _.uniqWith(appModels.concat(pluginsModels, componentModels), _.isEqual);

definition.associations.push({
  alias: key,
  targetUid: '*',
fork icon0
star icon0
watch icon1

429
430
431
432
433
434
435
436
437
438
439
            res =  getPathItems(document,1);
            break;
        default:
            break;
    }
    res = _.uniqWith(res,_.isEqual);
    return res;
}


module.exports = { findType }
fork icon0
star icon0
watch icon1

45
46
47
48
49
50
51
52
53
54
 * uniqProperties from array
 * @param {*} properties 
 * @returns Unique array object
 */
function uniqProperties(properties) {
  const arr = _.uniqWith(properties, _.isEqual)
  return _.filter(arr, (a) => {
    if(a != null)
      return a.length > 0
    return false
fork icon0
star icon0
watch icon0

476
477
478
479
480
481
482
483
484
485
486
487
console.log('uniqBy2--->', uniqBy2);
//uniqBy2---> [ { x: 1 }, { x: 2 } ]


//_.uniqWith(array,[comparator])
let uniqWithArr = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
let uniqWith1 = _.uniqWith(uniqWithArr, _.isEqual);
console.log('uniqWith1--->', uniqWith1);
//uniqWith1---> [ { x: 1, y: 2 }, { x: 2, y: 1 } ]


//_.unzip(array)
fork icon0
star icon0
watch icon0

397
398
399
400
401
402
403
404
405
406
        });
    }
}

// Array of facts of this category
// Remove duplicates using lodash's _.uniqWith() then sort by the alphabetical order of 'prettyName'
collatedCancerFactObj.facts = _.sortBy(_.uniqWith(factsArr, _.isEqual), ['name']);

// Add collatedFactObj to allCollatedFacts only when the facts array is not empty after all the above filtering
// E.g., treatment facts can be an empty array if the treatements are OtherTherapeuticProcedure and OtherMedication
fork icon0
star icon0
watch icon0

+ 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)