Skip to content

Commit

Permalink
Merge pull request #155 from MikeBeloborodov/7_kyu_difference_of_squares
Browse files Browse the repository at this point in the history
difference of squares
  • Loading branch information
MikeBeloborodov committed Jun 10, 2024
2 parents e0a6c7a + 6e1f6a2 commit 5672f1a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
5 changes: 5 additions & 0 deletions 7_kyu/difference_of_squares/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Difference Of Squares

https://www.codewars.com/kata/558f9f51e85b46e9fa000025

![description](./description.jpg "Description")
Binary file added 7_kyu/difference_of_squares/description.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions 7_kyu/difference_of_squares/difference_of_squares.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { differenceOfSquares } from "./difference_of_squares";

describe("test cases", () => {
it("should return 170", () => expect(differenceOfSquares(5)).toBe(170));
});
16 changes: 16 additions & 0 deletions 7_kyu/difference_of_squares/difference_of_squares.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const differenceOfSquares = (n: number) => {
const squareOfTheSum = Math.pow(
Array(n)
.fill(1)
.map((_, index) => index + 1)
.reduce((sum, next) => sum + next, 0),
2,
);

const sumOfSquares = Array(n)
.fill(1)
.map((_, index) => Math.pow(index + 1, 2))
.reduce((sum, next) => sum + next, 0);

return squareOfTheSum - sumOfSquares;
};
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ npm run push "$description"

### Katas solved

`Total`: 157
`Total`: 158
\
`8_kyu`: 51
\
`7_kyu`: 55
`7_kyu`: 56
\
`6_kyu`: 38
\
Expand Down

0 comments on commit 5672f1a

Please sign in to comment.