mirror of
https://gitlab.com/mfocko/CodeWars.git
synced 2024-11-24 09:41:55 +01:00
6kyu(js): add «The 5 Love Languages»
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
c9d717eee3
commit
0409d2cc4d
2 changed files with 32 additions and 0 deletions
31
6kyu/the_5_love_languages/solution.js
Normal file
31
6kyu/the_5_love_languages/solution.js
Normal 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;
|
||||||
|
}
|
|
@ -205,6 +205,7 @@
|
||||||
- [Halloween: trick or treat!](https://www.codewars.com/kata/581302bbbee85709d00002ae) - [solution](6kyu/halloween_trick_or_treat)
|
- [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)
|
- [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)
|
- [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
|
### Java
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue