Skip to content

Commit 232be72

Browse files
committed
add exercise1
1 parent 5dae18d commit 232be72

31 files changed

+406
-0
lines changed

exercise1/problem1/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Problem 1
2+
3+
Create a function that will return an integer number corresponding to the amount of digits in the given integer num.
4+
5+
```js
6+
console.log(numOfDigits(1000)) // 4
7+
8+
console.log(numOfDigits(12)) // 2
9+
10+
console.log(numOfDigits(1305981031)) // 10
11+
12+
console.log(numOfDigits(0)) // 1
13+
```

exercise1/problem1/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function numOfDigits(int) {
2+
// Your code
3+
}
4+
5+
export default numOfDigits;

exercise1/problem1/index.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { describe, expect, test } from "vitest";
2+
import numOfDigits from "./index";
3+
4+
describe("exercise1 - problem1", () => {
5+
test.each([
6+
{ int: 13124, expected: 5 },
7+
{ int: 0, expected: 1 },
8+
{ int: -12381428, expected: 8 },
9+
{ int: 12, expected: 2 },
10+
{ int: 42, expected: 2 },
11+
{ int: 1000, expected: 4 },
12+
{ int: 136, expected: 3 },
13+
{ int: 1000000000, expected: 10 },
14+
{ int: 2147483647, expected: 10 },
15+
{ int: -2147483647, expected: 10 },
16+
])(".numOfDigits($int)", ({ int, expected }) => {
17+
expect(numOfDigits(int)).toBe(expected);
18+
});
19+
});

exercise1/problem10/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Problem 10
2+
3+
Write a function that changes every letter to the next letter:
4+
5+
* "a" becomes "b"
6+
* "b" becomes "c"
7+
* "d" becomes "e"
8+
* and so on ...
9+
10+
```js
11+
console.log(move("hello")) // "ifmmp"
12+
13+
console.log(move("bye")) // "czf"
14+
15+
console.log(move("welcome")) // "xfmdpnf"
16+
```

exercise1/problem10/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function move() {
2+
// Your code
3+
}
4+
5+
export default move;

exercise1/problem10/index.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { describe, expect, test } from "vitest";
2+
import move from "./index";
3+
4+
describe("exercise1 - problem10", () => {
5+
test.each([
6+
{ text: "hello", expected: "ifmmp" },
7+
{ text: "lol", expected: "mpm" },
8+
{ text: "bye", expected: "czf" },
9+
])(".move($text)", ({ text, expected }) => {
10+
expect(move(text)).toBe(expected);
11+
});
12+
});

exercise1/problem2/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Problem 2
2+
3+
Create a function that validates whether a number `n` is within the bounds of lower and upper. Return `false` if `n` is
4+
not an integer.
5+
6+
```js
7+
console.log(intWithinBounds(3, 1, 9)) // true
8+
9+
console.log(intWithinBounds(6, 1, 6)) // false
10+
11+
console.log(intWithinBounds(4.5, 3, 8)) // false
12+
```

exercise1/problem2/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function intWithinBounds() {
2+
// Your code
3+
}
4+
5+
export default intWithinBounds;

exercise1/problem2/index.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { describe, expect, test } from "vitest";
2+
import intWithinBounds from "./index";
3+
4+
describe("exercise1 - problem2", () => {
5+
test.each([
6+
{ num: 3, lower: 1, upper: 9, expected: true },
7+
{ num: 6, lower: 1, upper: 6, expected: false },
8+
{ num: 4.5, lower: 3, upper: 8, expected: false },
9+
{ num: -5, lower: 10, upper: 6, expected: false },
10+
{ num: 4, lower: 0, upper: 0, expected: false },
11+
{ num: 10, lower: 9, upper: 11, expected: true },
12+
{ num: 6.3, lower: 2, upper: 6, expected: false },
13+
{ num: 6.3, lower: 2, upper: 10, expected: false },
14+
{ num: 9, lower: 2, upper: 3, expected: false },
15+
{ num: 9, lower: 9, upper: 9, expected: false },
16+
])(
17+
".intWithinBounds($num, $lower, $upper)",
18+
({ num, lower, upper, expected }) => {
19+
expect(intWithinBounds(num, lower, upper)).toBe(expected);
20+
}
21+
);
22+
});

exercise1/problem3/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Problem 3
2+
3+
Write a function that takes a positive integer `num` and calculates how many dots exist in a pentagonal shape around the
4+
center dot on the Nth iteration.
5+
6+
In the image below you can see the first iteration is only a single dot. On the second, there are 6 dots. On the third,
7+
there are 16 dots, and on the fourth there are 31 dots.
8+
9+
![example](pentagonal_number.png)
10+
11+
Return the number of dots that exist in the whole pentagon on the _Nth_ iteration.
12+
13+
```js
14+
console.log(pentagonal(1)) // 1
15+
16+
console.log(pentagonal(2)) // 6
17+
18+
console.log(pentagonal(3)) // 16
19+
20+
console.log(pentagonal(8)) // 141
21+
```

0 commit comments

Comments
 (0)