From 0409d2cc4db55d581c14832f8b4ff4ee2b541c97 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Fri, 26 Jul 2024 15:08:48 +0200 Subject: [PATCH] =?UTF-8?q?6kyu(js):=20add=20=C2=ABThe=205=20Love=20Langua?= =?UTF-8?q?ges=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matej Focko --- 6kyu/the_5_love_languages/solution.js | 31 +++++++++++++++++++++++++++ README.md | 1 + 2 files changed, 32 insertions(+) create mode 100644 6kyu/the_5_love_languages/solution.js diff --git a/6kyu/the_5_love_languages/solution.js b/6kyu/the_5_love_languages/solution.js new file mode 100644 index 0000000..a5d171d --- /dev/null +++ b/6kyu/the_5_love_languages/solution.js @@ -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; +} diff --git a/README.md b/README.md index ea4ec67..e98a5ea 100644 --- a/README.md +++ b/README.md @@ -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