From 8900e70af9c7c98b3f8c39769e3133cbce02768c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franco=20Sebasti=C3=A1n=20Genre?= <84336216+francogenre@users.noreply.github.com> Date: Mon, 13 Feb 2023 21:54:59 -0300 Subject: [PATCH] Update How much coffee do you need_.js --- 7-kyu-part1/How much coffee do you need_.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/7-kyu-part1/How much coffee do you need_.js b/7-kyu-part1/How much coffee do you need_.js index d3bbe207..429a2939 100644 --- a/7-kyu-part1/How much coffee do you need_.js +++ b/7-kyu-part1/How much coffee do you need_.js @@ -14,11 +14,28 @@ You just watch a movie ('movie'). Other events can be present and it will be represent by arbitrary string, just ignore this one. -Each event can be downcase/lowercase, or uppercase. If it is downcase/lowercase you need 1 coffee by events and if it is uppercase you need 2 coffees. +Each event canbe downcase/lowercase, or uppercase. If it is downcase/lowercase you need 1 coffee by events and if it is uppercase you need 2 coffees. */ + function howMuchCoffee(events) { const arr = events .filter(v => /^(cw|dog|cat|movie)$/.test(v.toLowerCase())) .reduce((a, b) => (/[a-z]/.test(b[0]) ? a + 1 : a + 2), 0); return arr < 4 ? arr : "You need extra sleep"; } + +/* +Long Solution: + +function howMuchCoffee(e) { + let count = 0; + for (let i = 0; i < e.length; ++i) + { + if (e[i] == 'cw' || e[i] == 'cat' || e[i] == 'dog' || e[i] == 'movie') + count++; + if (e[i] == 'CW' || e[i] == 'CAT' || e[i] == 'DOG' || e[i] == 'MOVIE') + count += 2; + } + return count > 3 ? 'You need extra sleep' : count; +} +*/