Skip to content

Commit

Permalink
Square(n) Sum
Browse files Browse the repository at this point in the history
  • Loading branch information
PheRum committed Jun 20, 2024
1 parent 6109353 commit 86f70b8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions 8_kyu/Square(n) Sum/README.md
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 9 additions & 0 deletions 8_kyu/Square(n) Sum/index.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
3 changes: 3 additions & 0 deletions 8_kyu/Square(n) Sum/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function squareSum(numbers: number[]): number {
return numbers.reduce((a, b) => a + Math.pow(b, 2), 0);
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down

0 comments on commit 86f70b8

Please sign in to comment.