1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-12-22 11:51:24 +01:00

6kyu(js): add «The 5 Love Languages»

Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2024-07-26 15:08:48 +02:00
parent c9d717eee3
commit 0409d2cc4d
Signed by: mfocko
GPG key ID: 7C47D46246790496
2 changed files with 32 additions and 0 deletions

View file

@ -0,0 +1,31 @@
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;
}

View file

@ -205,6 +205,7 @@
- [Halloween: trick or treat!](https://www.codewars.com/kata/581302bbbee85709d00002ae) - [solution](6kyu/halloween_trick_or_treat)
- [Build Tower Advanced](https://www.codewars.com/kata/57675f3dedc6f728ee000256) - [solution](6kyu/build_tower_advanced)
- [Evil Autocorrect Prank](https://www.codewars.com/kata/538ae2eb7a4ba8c99b000439) - [solution](6kyu/evil_autocorrect_prank)
- [The 5 Love Languages](https://www.codewars.com/kata/5aa7a581fd8c06b552000177) - [solution](6kyu/the_5_love_languages)
### Java