message this user

Name

matchalgo

Global

/* Ideal Match Algorithm with ranks in databased and readwrite cached
* 
* The idea is to ask out the top person in your rank
* If you are their top person they will say yes and you are matched
* If they have others they like more they will ask them until they are denied
*
*/

function myidealmatch(id,rankings) {
 var stackset = new Set();
 var myrank = rankings[id];
 var retr=null;
 myrank.some(willask=>{
  var match=domatch(id,willask,stackset,rankings)
  if(match) {
   retr=willask;
   return true;
  }
 });
 return retr;
}

function domatch(asker,asked,stackset,rankings) {
 if(stackset.has(asked)) {
  return false;
 }
 console.log('asked',asked);
 var indexOf=rankings[asked].indexOf(asker);
 if(indexOf==-1) {
  return false;
 }
 var likemore = rankings[asked].slice(0,indexOf);
 stackset.add(asker); //We are getting recursive, let's not loop in on ourselves;
 var badnews = likemore.some(compeditor=>{
  return domatch(asked,compeditor,stackset,rankings);
 });
 return !badnews;
}

Init

startChat('');

Build

wchat