Skip to content

Instantly share code, notes, and snippets.

@hunterwilhelm
Created October 3, 2021 00:05
Show Gist options
  • Save hunterwilhelm/1a63162028a69d13fb27e21aff4276f7 to your computer and use it in GitHub Desktop.
Save hunterwilhelm/1a63162028a69d13fb27e21aff4276f7 to your computer and use it in GitHub Desktop.
The least disliked ranking algorithm
// The Dislike Total (DT) is calculated
// by totaling the below 'mean' differences.
// The lowest DT is the winner.
function calcLeastDisliked(multiArray) {
const sum = array=>array.reduce((a,b)=>a + b, 0);
const singleArray = [].concat(...multiArray);
const avg = sum(singleArray) / singleArray.length;
return multiArray.map(ratings=>{
const belowAvgRatings = ratings.filter(x=>avg > x, ratings);
const DT = avg * belowAvgRatings.length - sum(belowAvgRatings);
console.log(ratings, DT);
return DT;
});
}
@hunterwilhelm
Copy link
Author

hunterwilhelm commented Oct 3, 2021

Why?

When people are voting on things, a popular vote usually ends up with a polarized outcome. Some people will really love it and others will hate it. This algorithm takes into account that we want the thing that is mostly okay with everybody.

Example

let ratings = [
    [7,6,7,9], // option 0 ratings
    [10,6,9,5], // option 1 ratings
    [3,5,5,3], // ...
    [5,8,5,9]
];
calcLeastDisliked(ratings);

returns [0.375, 1.75, 9.5, 2.75]
prints

[7, 6, 7, 9] 0.375
[10, 6, 9, 5] 1.75
[3, 5, 5, 3] 9.5
[5, 8, 5, 9] 2.75

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment