Skip to content

Instantly share code, notes, and snippets.

@gemmadlou
Created October 30, 2016 01:12
Show Gist options
  • Select an option

  • Save gemmadlou/9082ca715a6ebef3f043ac4159929fb2 to your computer and use it in GitHub Desktop.

Select an option

Save gemmadlou/9082ca715a6ebef3f043ac4159929fb2 to your computer and use it in GitHub Desktop.
Score Generation - Meetings
var tr = require('transduce');
var R = require('ramda');
var Delegates = [
{ 'name': 'John', likes: ['Cars','Computers']},
{ 'name': 'Lisa', likes: ['Internet']},
{ 'name': 'Amy', likes: []}
];
var Suppliers = [
{ company: 'Google', likes: ['Internet']},
{ company: 'Tesla', likes: ['Cars'] }
]
// Create Scores
// 1) Find similar Likes
var AllAttendees = Delegates.concat(Suppliers);
var AllAttendeeLikes = tr.into([], tr.cat, AllAttendees.map(function(attendee) {
return attendee.likes.map(function(like) {
return {
attendee: (attendee.company) ? attendee.company : attendee.name,
like: like,
type: (attendee.company) ? 'supplier' : 'delegate'
}
});
}));
var AllLikes = R.uniq(tr.into([], tr.cat, AllAttendees.map(function(attendee) {
return attendee.likes;
})));
var CommonLikes = tr.into([], AllLikes.map(function(like) {
return AllAttendeeLikes.filter(function(attendee) {
return attendee.like === like;
});
}));
// var ConnectedAttendees = Delegates.map(function(delegate) {
// return Suppliers.map(function(supplier) {
// return AllLikes.map(function(like) {
// return (delegate.likes.indexOf(like) > -1) && (supplier.likes.indexOf(like) > -1)
// });
// });
// });
var flatten = function(array) {
return R.flatten(array);
}
var ConnectedAttendees = function(Delegates, Suppliers) {
return Delegates.map(function(delegate) {
return Suppliers.map(function(supplier){
var likes = R.intersection(delegate.likes, supplier.likes);
return obj = {
delegate: delegate.name,
supplier: supplier.company,
likes: likes,
score: likes.length
}
});
});
}
var NumberOfMutualLikesOver = function(array, num) {
return R.filter(function(match) {
return match.likes.length > num;
}, array);
}
var Score = NumberOfMutualLikesOver(flatten(ConnectedAttendees(Delegates, Suppliers)), 0);
// What if the attendee has no likes
console.log(Score);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment