From 86f70b8d1418440d241b1e1596811ff71b1e7772 Mon Sep 17 00:00:00 2001 From: Valery Malyshev Date: Fri, 21 Jun 2024 02:27:42 +0300 Subject: [PATCH] Square(n) Sum --- 8_kyu/Square(n) Sum/README.md | 5 +++++ 8_kyu/Square(n) Sum/index.test.ts | 9 +++++++++ 8_kyu/Square(n) Sum/index.ts | 3 +++ README.md | 4 ++-- 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 8_kyu/Square(n) Sum/README.md create mode 100644 8_kyu/Square(n) Sum/index.test.ts create mode 100644 8_kyu/Square(n) Sum/index.ts diff --git a/8_kyu/Square(n) Sum/README.md b/8_kyu/Square(n) Sum/README.md new file mode 100644 index 0000000..5f2f0bc --- /dev/null +++ b/8_kyu/Square(n) Sum/README.md @@ -0,0 +1,5 @@ +## Square(n) Sum + +https://www.codewars.com/kata/515e271a311df0350d00000f + +Complete the square sum function so that it squares each number passed into it and then sums the results together. diff --git a/8_kyu/Square(n) Sum/index.test.ts b/8_kyu/Square(n) Sum/index.test.ts new file mode 100644 index 0000000..48a9ea2 --- /dev/null +++ b/8_kyu/Square(n) Sum/index.test.ts @@ -0,0 +1,9 @@ +import { squareSum } from "./index"; + +describe("Tests", () => { + it("example", () => { + expect(squareSum([1, 2])).toBe(5); + expect(squareSum([0, 3, 4, 5])).toBe(50); + expect(squareSum([])).toBe(0); + }); +}); diff --git a/8_kyu/Square(n) Sum/index.ts b/8_kyu/Square(n) Sum/index.ts new file mode 100644 index 0000000..b12415d --- /dev/null +++ b/8_kyu/Square(n) Sum/index.ts @@ -0,0 +1,3 @@ +export function squareSum(numbers: number[]): number { + return numbers.reduce((a, b) => a + Math.pow(b, 2), 0); +} diff --git a/README.md b/README.md index c3b039f..8feb767 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ ### Katas solved -`Total`: 122 \ -`8_kyu`: 97 \ +`Total`: 123 \ +`8_kyu`: 98 \ `7_kyu`: 16 \ `6_kyu`: 9 \ `5_kyu`: 0 \