From 69da64721103b2fff2c1e0db0c8ee87f0f924b0d Mon Sep 17 00:00:00 2001 From: Valery Malyshev Date: Sat, 15 Jun 2024 03:19:22 +0300 Subject: [PATCH] How good are you really? --- 8_kyu/How good are you really?/README.md | 14 ++++++++++++ 8_kyu/How good are you really?/index.test.ts | 23 ++++++++++++++++++++ 8_kyu/How good are you really?/index.ts | 5 +++++ README.md | 4 ++-- kata.md | 1 - 5 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 8_kyu/How good are you really?/README.md create mode 100644 8_kyu/How good are you really?/index.test.ts create mode 100644 8_kyu/How good are you really?/index.ts diff --git a/8_kyu/How good are you really?/README.md b/8_kyu/How good are you really?/README.md new file mode 100644 index 0000000..b389b2e --- /dev/null +++ b/8_kyu/How good are you really?/README.md @@ -0,0 +1,14 @@ +## How good are you really? + +https://www.codewars.com/kata/5601409514fc93442500010b + +There was a test in your class and you passed it. Congratulations! + +But you're an ambitious person. You want to know if you're better than the average student in your class. + +You receive an array with your peers' test scores. Now calculate the average and compare your score! + +Return true if you're better, else false! + +Note: +Your points are not included in the array of your class's points. Do not forget them when calculating the average score! diff --git a/8_kyu/How good are you really?/index.test.ts b/8_kyu/How good are you really?/index.test.ts new file mode 100644 index 0000000..314ff8e --- /dev/null +++ b/8_kyu/How good are you really?/index.test.ts @@ -0,0 +1,23 @@ +import { betterThanAverage } from "./index"; + +describe("Tests", () => { + it("betterThanAverage([2, 3], 5) should return True", () => { + expect(betterThanAverage([2, 3], 5)).toBe(true); + }); + + it("betterThanAverage([100, 40, 34, 57, 29, 72, 57, 88], 75) should return True", () => { + expect(betterThanAverage([100, 40, 34, 57, 29, 72, 57, 88], 75)).toBe(true); + }); + + it("betterThanAverage([12, 23, 34, 45, 56, 67, 78, 89, 90], 9) should return False", () => { + expect(betterThanAverage([12, 23, 34, 45, 56, 67, 78, 89, 90], 9)).toBe(false); + }); + + it("betterThanAverage([41, 75, 72, 56, 80, 82, 81, 33], 50) should return False", () => { + expect(betterThanAverage([41, 75, 72, 56, 80, 82, 81, 33], 50)).toBe(false); + }); + + it("betterThanAverage([29, 55, 74, 60, 11, 90, 67, 28], 21) should return False", () => { + expect(betterThanAverage([29, 55, 74, 60, 11, 90, 67, 28], 21)).toBe(false); + }); +}); diff --git a/8_kyu/How good are you really?/index.ts b/8_kyu/How good are you really?/index.ts new file mode 100644 index 0000000..4b1b0d2 --- /dev/null +++ b/8_kyu/How good are you really?/index.ts @@ -0,0 +1,5 @@ +export function betterThanAverage(classPoints: number[], yourPoints: number): boolean { + const average = classPoints.reduce((a, b) => a + b, 0) / classPoints.length; + + return average <= yourPoints; +} diff --git a/README.md b/README.md index f6cd37c..a6d3c9c 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ ### Katas solved -`Total`: 94 \ -`8_kyu`: 77 \ +`Total`: 95 \ +`8_kyu`: 78 \ `7_kyu`: 13 \ `6_kyu`: 4 \ `5_kyu`: 0 \ diff --git a/kata.md b/kata.md index 74d4312..1040549 100644 --- a/kata.md +++ b/kata.md @@ -1,4 +1,3 @@ -8 kyu - How good are you really? - https://www.codewars.com/kata/5601409514fc93442500010b 8 kyu - Simple multiplication - https://www.codewars.com/kata/583710ccaa6717322c000105 8 kyu - Convert a String to a Number! - https://www.codewars.com/kata/544675c6f971f7399a000e79 8 kyu - CSV representation of array - https://www.codewars.com/kata/5a34af40e1ce0eb1f5000036