155
rated 0 times
[
162]
[
7]
/ answers: 1 / hits: 20845
/ 8 Years ago, fri, november 25, 2016, 12:00:00
Here in this snippet i am stuck as in _.uniqBy(array,iteratee)
,this
iteratee
can be a function or a string at the same time- Where to put the condition to check uniqness on the property because itratee function can be anything
var sourceArray = [ { id: 1, name: 'bob' },
{ id: 1, name: 'bill' },
{ id: 1, name: 'bill' } ,
{id: 2,name: 'silly'},
{id: 2,name: 'billy'}]
function uniqBy (inputArray, callback) {
return inputArray.filter(callback)
}
var inputFunc = function (item) {
return item.name
}
// var destArray = _.uniqBy(sourceArray,'name')
var destArray = uniqBy(sourceArray, inputFunc)
console.log('destArray', destArray)
Any leads on this will be most appreciated.
More From » arrays