Skip to content

Instantly share code, notes, and snippets.

@MarcBalaban
Created January 6, 2019 22:01
Show Gist options
  • Save MarcBalaban/0e6a2a233ac621db3c1c56d2aff6aa8d to your computer and use it in GitHub Desktop.
Save MarcBalaban/0e6a2a233ac621db3c1c56d2aff6aa8d to your computer and use it in GitHub Desktop.
Decision Formula
function decisionFormula (activities, n) {
var objMap = {};
activities.forEach(item => {
objMap[item] = 0;
})
for (var i = 0; i < 100; i++) {
objMap[activities[Math.floor(Math.random() * activities.length)]]++;
}
var sortable = [];
for (var activity in objMap) {
sortable.push([activity, objMap[activity]]);
}
sortable.sort(function(a, b) {
return b[1] - a[1];
});
var sortedList = sortable.map((item, i) =>
`${i + 1}) ${item[0]} | ${item[1]} votes`
);
var activitiesToDo = sortedList.splice(0,n).join('\n')
var missedActivities = sortedList.join('\n')
return `
Hurray! You're going to do these Activities!
--------------------------------------
${activitiesToDo}
======================================
So close! but maybe do these activities another time:
--------------------------------------
${missedActivities}
`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment