From 757edc1f748364677d8588d9673f853a5a9b085e Mon Sep 17 00:00:00 2001 From: Valery Malyshev Date: Mon, 20 May 2024 00:57:43 +0300 Subject: [PATCH] Well of Ideas - Easy Version --- 8_kyu/Well of Ideas - Easy Version/README.md | 8 ++++++++ 8_kyu/Well of Ideas - Easy Version/index.test.ts | 9 +++++++++ 8_kyu/Well of Ideas - Easy Version/index.ts | 13 +++++++++++++ README.md | 4 ++-- 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 8_kyu/Well of Ideas - Easy Version/README.md create mode 100644 8_kyu/Well of Ideas - Easy Version/index.test.ts create mode 100644 8_kyu/Well of Ideas - Easy Version/index.ts diff --git a/8_kyu/Well of Ideas - Easy Version/README.md b/8_kyu/Well of Ideas - Easy Version/README.md new file mode 100644 index 0000000..4b2da27 --- /dev/null +++ b/8_kyu/Well of Ideas - Easy Version/README.md @@ -0,0 +1,8 @@ +## Well of Ideas - Easy Version + +https://www.codewars.com/kata/57f222ce69e09c3630000212 + +For every good kata idea there seem to be quite a few bad ones! + +In this kata you need to check the provided array (x) for good ideas 'good' and bad ideas 'bad'. If there are one or two good ideas, +return 'Publish!', if there are more than 2 return 'I smell a series!'. If there are no good ideas, as is often the case, return 'Fail!'. diff --git a/8_kyu/Well of Ideas - Easy Version/index.test.ts b/8_kyu/Well of Ideas - Easy Version/index.test.ts new file mode 100644 index 0000000..780488f --- /dev/null +++ b/8_kyu/Well of Ideas - Easy Version/index.test.ts @@ -0,0 +1,9 @@ +import { well } from "./index"; + +describe("Tests", () => { + it("example", () => { + expect(well(["bad", "bad", "bad"])).toBe("Fail!"); + expect(well(["good", "bad", "bad", "bad", "bad"])).toBe("Publish!"); + expect(well(["good", "bad", "bad", "bad", "bad", "good", "bad", "bad", "good"])).toBe("I smell a series!"); + }); +}); diff --git a/8_kyu/Well of Ideas - Easy Version/index.ts b/8_kyu/Well of Ideas - Easy Version/index.ts new file mode 100644 index 0000000..66229ad --- /dev/null +++ b/8_kyu/Well of Ideas - Easy Version/index.ts @@ -0,0 +1,13 @@ +type WellType = "good" | "bad"; + +export function well(x: WellType[]) { + const good = x.filter((n) => n === "good").length; + + if (good && good <= 2) { + return "Publish!"; + } + if (good > 2) { + return "I smell a series!"; + } + return "Fail!"; +} diff --git a/README.md b/README.md index 5a07b29..681edfd 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ ### Katas solved -`Total`: 39 \ -`8_kyu`: 37 \ +`Total`: 40 \ +`8_kyu`: 38 \ `7_kyu`: 0 \ `6_kyu`: 2 \ `5_kyu`: 0 \