Is there a javascript or coffeescript function (or maybe an extension of the underscore groupBy function) that receives as parameters an array and an equivalence comparator (a boolean function with TWO arguments, not just ONE argument) and groups the array elements based on this equivalence comparator?
As an example of what I want:
areEquivalent = (p1, p2) ->
p1.birthYear == p2.birthYear and
p1.birthPlace == p2.birthPlace and
p1.gender == p2.gender
p1 = {name:'Anna', birthYear: 1990, birthPlace: 'Alaska', gender: 'female', hasCar: true, hasChildren: false}
p2 = {name:'John', birthYear: 1990, birthPlace: 'Alaska', gender: 'male', hasCar: true, hasChildren: false}
p3 = {name:'Dora', birthYear: 1980, birthPlace: 'Hawaii', gender: 'female', hasCar: true, hasChildren: true}
p4 = {name:'Lumi', birthYear: 1980, birthPlace: 'Hawaii', gender: 'female', hasCar: false, hasChildren: false}
p5 = {name:'Jack', birthYear: 1990, birthPlace: 'Alaska', gender: 'male', hasCar: false, hasChildren: false}
console.log areEquivalent p1, p2
# false
console.log areEquivalent p3, p4
# true
people = [p1, p2, p3, p4, p5]
console.log _.groupEquivalentObjects(people, areEquivalent)
# [ [p1], [p2,p5], [p3,p4] ]