Skip to content

Commit

Permalink
Sum Mixed Array
Browse files Browse the repository at this point in the history
  • Loading branch information
PheRum committed May 19, 2024
1 parent a275965 commit 9f34579
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
7 changes: 7 additions & 0 deletions 8_kyu/Sum Mixed Array/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Sum Mixed Array

https://www.codewars.com/kata/57eaeb9578748ff92a000009

Given an array of integers as strings and numbers, return the sum of the array values as if all were numbers.

Return your answer as a number.
9 changes: 9 additions & 0 deletions 8_kyu/Sum Mixed Array/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { sumMix } from "./index";

describe("Tests", () => {
it("Testing for fixed tests", () => {
expect(sumMix([9, 3, "7", "3"])).toBe(22);
expect(sumMix(["5", "0", 9, 3, 2, 1, "9", 6, 7])).toBe(42);
expect(sumMix(["3", 6, 6, 0, "5", 8, 5, "6", 2, "0"])).toBe(41);
});
});
3 changes: 3 additions & 0 deletions 8_kyu/Sum Mixed Array/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function sumMix(x: (string | number)[]): number {
return x.map((el) => Number(el)).reduce((acc, cur) => acc + cur, 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`: 44 \
`8_kyu`: 42 \
`Total`: 45 \
`8_kyu`: 43 \
`7_kyu`: 0 \
`6_kyu`: 2 \
`5_kyu`: 0 \
Expand Down

0 comments on commit 9f34579

Please sign in to comment.