Created
October 27, 2017 17:28
-
-
Save backnotprop/25a5977c9ab0a7fd0205f8a13a3a3596 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// iterates over the process of sending, accepting, and rejecting proposals | |
function proposalProcess(sender, receiver, receiverRank) { | |
// we now need to check to see if the receiver has accepted proposals and | |
// how the receiver ranks the sender of the proposal | |
let indexOfsender = _.findIndex(receiver.choices, p => { return p.id == sender.id; }); | |
// create shortcut to senders object in receiver's list | |
let senderRank = receiver.choices[indexOfsender].strength; | |
if(receiver.hasAcceptedReceivedProposal) { | |
// need to compare against accept proposal | |
if(receiver.acceptedReceivedRank > senderRank) { | |
// rejected because offer has already been accept by someone with higher preference | |
rejectOffer(sender, receiver); | |
} else { | |
// define rejected before received accepts a new offer | |
let rejected = _DB[receiver.acceptedReceivedID].id; | |
acceptOffer(sender, receiver, receiverRank, senderRank); | |
// accepted because the sender outranks the previously accepted proposal | |
// the previous proposal now needs to be denied | |
rejectOffer(_DB[rejected], receiver); | |
} | |
} else { | |
// accepted because he does not have any accepted proposal | |
acceptOffer(sender, receiver, receiverRank, senderRank); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment