Skip to content

Commit

Permalink
add exercise3
Browse files Browse the repository at this point in the history
  • Loading branch information
talgat-ruby committed Oct 17, 2023
1 parent 8489d75 commit f14c78d
Show file tree
Hide file tree
Showing 31 changed files with 417 additions and 0 deletions.
13 changes: 13 additions & 0 deletions exercise3/problem1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Problem 1

Create a function that concatenates all argument arrays.

```js
console.log(concat([1, 2, 3], [4, 5], [6, 7])) // [1, 2, 3, 4, 5, 6, 7]

console.log(concat([1], [2], [3], [4], [5], [6], [7])) // [1, 2, 3, 4, 5, 6, 7]

console.log(concat([1, 2], [3, 4])) // [1, 2, 3, 4]

console.log(concat([4, 4, 4, 4, 4])) // [4, 4, 4, 4, 4]
```
5 changes: 5 additions & 0 deletions exercise3/problem1/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function concat() {
// Your code
}

export default concat;
30 changes: 30 additions & 0 deletions exercise3/problem1/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {describe, expect, test}
import concat from "./index";

describe("exercise2 - problem1", () => {
test.each([
{
args: [
[1, 2, 3],
[4, 5],
[6, 7],
],
expected: [1, 2, 3, 4, 5, 6, 7],
},
{
args: [[1], [2], [3], [4], [5], [6], [7]],
expected: [1, 2, 3, 4, 5, 6, 7],
},
{
args: [
[1, 2],
[3, 4],
],
expected: [1, 2, 3, 4],
},
{args: [[4, 4, 4, 4, 4]], expected: [4, 4, 4, 4, 4]},
{args: [["a"], ["b", "c"]], expected: ["a", "b", "c"]},
])(".concat(...$args)", ({args, expected}) => {
expect(concat(...args)).toEqual(expected);
});
});
16 changes: 16 additions & 0 deletions exercise3/problem10/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Problem 10

Write a function that changes every letter to the next letter:

* "a" becomes "b"
* "b" becomes "c"
* "d" becomes "e"
* and so on ...

```js
console.log(move("hello")) // "ifmmp"

console.log(move("bye")) // "czf"

console.log(move("welcome")) // "xfmdpnf"
```
5 changes: 5 additions & 0 deletions exercise3/problem10/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function move() {
// Your code
}

export default move;
12 changes: 12 additions & 0 deletions exercise3/problem10/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {describe, expect, test}
import move from "./index";

describe("exercise1 - problem10", () => {
test.each([
{text: "hello", expected: "ifmmp"},
{text: "lol", expected: "mpm"},
{text: "bye", expected: "czf"},
])(".move($text)", ({text, expected}) => {
expect(move(text)).toBe(expected);
});
});
12 changes: 12 additions & 0 deletions exercise3/problem2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Problem 2

Create a function that validates whether a number `n` is within the bounds of lower and upper. Return `false` if `n` is
not an integer.

```js
console.log(intWithinBounds(3, 1, 9)) // true

console.log(intWithinBounds(6, 1, 6)) // false

console.log(intWithinBounds(4.5, 3, 8)) // false
```
5 changes: 5 additions & 0 deletions exercise3/problem2/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function intWithinBounds() {
// Your code
}

export default intWithinBounds;
22 changes: 22 additions & 0 deletions exercise3/problem2/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {describe, expect, test}
import intWithinBounds from "./index";

describe("exercise1 - problem2", () => {
test.each([
{num: 3, lower: 1, upper: 9, expected: true},
{num: 6, lower: 1, upper: 6, expected: false},
{num: 4.5, lower: 3, upper: 8, expected: false},
{num: -5, lower: 10, upper: 6, expected: true},
{num: 4, lower: 0, upper: 0, expected: false},
{num: 10, lower: 9, upper: 11, expected: true},
{num: 6.3, lower: 2, upper: 6, expected: false},
{num: 6.3, lower: 2, upper: 10, expected: false},
{num: 9, lower: 2, upper: 3, expected: false},
{num: 9, lower: 9, upper: 9, expected: false},
])(
".intWithinBounds($num, $lower, $upper)",
({num, lower, upper, expected}) => {
expect(intWithinBounds(num, lower, upper)).toBe(expected);
}
);
});
21 changes: 21 additions & 0 deletions exercise3/problem3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Problem 3

Write a function that takes a positive integer `num` and calculates how many dots exist in a pentagonal shape around the
center dot on the Nth iteration.

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,
there are 16 dots, and on the fourth there are 31 dots.

![example](pentagonal_number.png)

Return the number of dots that exist in the whole pentagon on the _Nth_ iteration.

```js
console.log(pentagonal(1)) // 1

console.log(pentagonal(2)) // 6

console.log(pentagonal(3)) // 16

console.log(pentagonal(8)) // 141
```
5 changes: 5 additions & 0 deletions exercise3/problem3/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function pentagonal() {
// Your code
}

export default pentagonal;
20 changes: 20 additions & 0 deletions exercise3/problem3/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {describe, expect, test}
import pentagonal from "./index";

describe("exercise1 - problem3", () => {
test.each([
{level: 1, expected: 1},
{level: 3, expected: 16},
{level: 8, expected: 141},
{level: 10, expected: 226},
{level: 15, expected: 526},
{level: 33, expected: 2641},
{level: 43, expected: 4516},
{level: 13, expected: 391},
{level: 50, expected: 6126},
{level: 62, expected: 9456},
{level: 21, expected: 1051},
])(".pentagonal($level)", ({level, expected}) => {
expect(pentagonal(level)).toBe(expected);
});
});
Binary file added exercise3/problem3/pentagonal_number.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions exercise3/problem4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Problem 4

Create a function that takes a string as an argument and converts the first character of each word to uppercase. Return
the newly formatted string.

```js
console.log(makeTitleCase("This is a title")) // "This Is A Title"

console.log(makeTitleCase("capitalize every word")) // "Capitalize Every Word"

console.log(makeTitleCase("I Like Pizza")) // "I Like Pizza"

console.log(makeTitleCase("PIZZA PIZZA PIZZA")) // "PIZZA PIZZA PIZZA"
```
5 changes: 5 additions & 0 deletions exercise3/problem4/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function makeTitleCase() {
// Your code
}

export default makeTitleCase;
38 changes: 38 additions & 0 deletions exercise3/problem4/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {describe, expect, test}
import makeTitleCase from "./index";

describe("exercise1 - problem4", () => {
test.each([
{text: "I am a title", expected: "I Am A Title"},
{text: "I AM A TITLE", expected: "I AM A TITLE"},
{text: "i aM a tITLE", expected: "I AM A TITLE"},
{
text: "the first letter of every word is capitalized",
expected: "The First Letter Of Every Word Is Capitalized",
},
{text: "I Like Pizza", expected: "I Like Pizza"},
{
text: "Don't count your ChiCKens BeFore They HatCh",
expected: "Don't Count Your ChiCKens BeFore They HatCh",
},
{
text: "All generalizations are false, including this one",
expected: "All Generalizations Are False, Including This One",
},
{
text: "Me and my wife lived happily for twenty years and then we met.",
expected:
"Me And My Wife Lived Happily For Twenty Years And Then We Met.",
},
{
text: "There are no stupid questions, just stupid people.",
expected: "There Are No Stupid Questions, Just Stupid People.",
},
{
text: "1f you c4n r34d 7h15, you r34lly n33d 2 g37 l41d",
expected: "1f You C4n R34d 7h15, You R34lly N33d 2 G37 L41d",
},
])('.makeTitleCase("$text")', ({text, expected}) => {
expect(makeTitleCase(text)).toBe(expected);
});
});
12 changes: 12 additions & 0 deletions exercise3/problem5/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Problem 5

Create a function that will remove the letters "a", "b" and "c" from the given string and return the modified version.
If the given string does not contain "a", "b", or "c", return `null`.

```js
console.log(removeABC("This might be a bit hard")) // "This might e it hrd"

console.log(removeABC("hello world!")) // null

console.log(removeABC("")) // null
```
5 changes: 5 additions & 0 deletions exercise3/problem5/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function removeABC() {
// Your code
}

export default removeABC;
17 changes: 17 additions & 0 deletions exercise3/problem5/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {describe, expect, test}
import removeABC from "./index";

describe("exercise1 - problem5", () => {
test.each([
{text: "This might be a bit hard", expected: "This might e it hrd"},
{text: "This is awesome", expected: "This is wesome"},
{text: "hello world!", expected: null},
{
text: "coding is fun!",
expected: "oding is fun!",
},
{text: "", expected: null},
])('.removeABC("$text")', ({text, expected}) => {
expect(removeABC(text)).toBe(expected);
});
});
12 changes: 12 additions & 0 deletions exercise3/problem6/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Problem 6

Write a function that inserts a white space between every instance of a lower character followed immediately by an upper
character.

```js
console.log(insertWhitespace("SheWalksToTheBeach")) // "She Walks To The Beach"

console.log(insertWhitespace("MarvinTalksTooMuch")) // "Marvin Talks Too Much"

console.log(insertWhitespace("TheGreatestUpsetInHistory")) // "The Greatest Upset In History"
```
5 changes: 5 additions & 0 deletions exercise3/problem6/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function insertWhitespace() {
// Your code
}

export default insertWhitespace;
20 changes: 20 additions & 0 deletions exercise3/problem6/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {describe, expect, test}
import insertWhitespace from "./index";

describe("exercise1 - problem6", () => {
test.each([
{text: "SheWalksToTheBeach", expected: "She Walks To The Beach"},
{text: "MarvinTalksTooMuch", expected: "Marvin Talks Too Much"},
{text: "HopelesslyDevotedToYou", expected: "Hopelessly Devoted To You"},
{
text: "EvenTheBestFallDownSometimes",
expected: "Even The Best Fall Down Sometimes",
},
{
text: "TheGreatestUpsetInHistory",
expected: "The Greatest Upset In History",
},
])(".insertWhitespace($text)", ({text, expected}) => {
expect(insertWhitespace(text)).toBe(expected);
});
});
15 changes: 15 additions & 0 deletions exercise3/problem7/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Problem 7

Create a function to check whether the given parameter is a primitive or not.

```js
console.log(isPrimitive(function add(x, y) {
return x + y
})) // true

console.log(isPrimitive(new RegExp('^[a-zA-Z0-9]+$', 'g'))) // true

console.log(isPrimitive(null)) // false

console.log(isPrimitive("")) // false
```
5 changes: 5 additions & 0 deletions exercise3/problem7/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function isPrimitve() {
// Your code
}

export default isPrimitve;
21 changes: 21 additions & 0 deletions exercise3/problem7/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {describe, expect, test}
import isPrimitive from "./index";

describe("exercise1 - problem7", () => {
test.each([
{arg: false, expected: true},
{arg: -123, expected: true},
{arg: 0, expected: true},
{arg: "12/12/2011", expected: true},
{arg: undefined, expected: true},
{arg: null, expected: true},
{arg: BigInt(9007199254740991), expected: true},
{arg: Symbol("hello"), expected: true},
{arg: new Date(), expected: false},
{arg: () => null, expected: false},
{arg: {}, expected: false},
{arg: [1, 2, 3], expected: false},
])(".isPrimitive($arg)", ({num, lower, upper, expected}) => {
expect(isPrimitive(num, lower, upper)).toBe(expected);
});
});
17 changes: 17 additions & 0 deletions exercise3/problem8/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Problem 8

Create a function that takes three values:

* `h` hours - as `1` arg
* `m` minutes - as `2` arg
* `s` seconds - as `3` arg

Return the value that's the __longest duration__. If equal take the last argument.

```js
console.log(longestTime(1, 59, 3598)) // 1

console.log(longestTime(2, 300, 15000)) // 300

console.log(longestTime(15, 955, 59400)) // 59400
```
5 changes: 5 additions & 0 deletions exercise3/problem8/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function longestTime() {
// Your code
}

export default longestTime;
Loading

0 comments on commit f14c78d

Please sign in to comment.