1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-09-16 20:56:57 +02:00
CodeWars/6kyu/the_5_love_languages/solution.js
Matej Focko 0409d2cc4d
6kyu(js): add «The 5 Love Languages»
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-07-26 15:08:48 +02:00

31 lines
618 B
JavaScript

function loveLanguage(partner, weeks) {
const options = ["words", "acts", "gifts", "time", "touch"];
const tries = 7 * weeks;
let counters = {
"words": 0,
"acts": 0,
"gifts": 0,
"time": 0,
"touch": 0,
};
for (let i = 0; i < tries; ++i) {
const choice = options[i % options.length];
if (partner.response(choice) == "positive") {
counters[choice]++;
}
}
let best = 0;
let bestChoice = null;
for (let choice of options) {
if (counters[choice] > best) {
best = counters[choice];
bestChoice = choice;
}
}
return bestChoice;
}