Skip to content

Commit

Permalink
Convert a String to a Number!
Browse files Browse the repository at this point in the history
  • Loading branch information
PheRum committed Jun 15, 2024
1 parent d4de607 commit 89e7dda
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
19 changes: 19 additions & 0 deletions 8_kyu/Convert a String to a Number!/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Convert a String to a Number!

https://www.codewars.com/kata/544675c6f971f7399a000e79

Note: This kata is inspired by Convert a Number to a String!. Try that one too.

Description
We need a function that can transform a string into a number. What ways of achieving this do you know?

Note: Don't worry, all inputs will be strings, and every string is a perfectly valid representation of an integral number.

Examples

```js
"1234" --> 1234
"605" --> 605
"1405" --> 1405
"-7" --> -7
```
10 changes: 10 additions & 0 deletions 8_kyu/Convert a String to a Number!/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { stringToNumber } from "./index";

describe("Tests", () => {
it("example", () => {
expect(stringToNumber("1234")).toBe(1234);
expect(stringToNumber("605")).toBe(605);
expect(stringToNumber("1405")).toBe(1405);
expect(stringToNumber("-7")).toBe(-7);
});
});
3 changes: 3 additions & 0 deletions 8_kyu/Convert a String to a Number!/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function stringToNumber(str: string): number {
return +str;
}
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`: 96 \
`8_kyu`: 79 \
`Total`: 97 \
`8_kyu`: 80 \
`7_kyu`: 13 \
`6_kyu`: 4 \
`5_kyu`: 0 \
Expand Down
1 change: 0 additions & 1 deletion kata.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
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
8 kyu - Reversed Strings - https://www.codewars.com/kata/5168bb5dfe9a00b126000018
8 kyu - String repeat - https://www.codewars.com/kata/57a0e5c372292dd76d000d7e
Expand Down

0 comments on commit 89e7dda

Please sign in to comment.