diff --git a/exercise3/problem1/README.md b/exercise3/problem1/README.md new file mode 100644 index 0000000..af3a6e6 --- /dev/null +++ b/exercise3/problem1/README.md @@ -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] +``` \ No newline at end of file diff --git a/exercise3/problem1/index.js b/exercise3/problem1/index.js new file mode 100644 index 0000000..8558a10 --- /dev/null +++ b/exercise3/problem1/index.js @@ -0,0 +1,5 @@ +function concat() { + // Your code +} + +export default concat; diff --git a/exercise3/problem1/index.test.js b/exercise3/problem1/index.test.js new file mode 100644 index 0000000..6e8bfb7 --- /dev/null +++ b/exercise3/problem1/index.test.js @@ -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); + }); +}); diff --git a/exercise3/problem10/README.md b/exercise3/problem10/README.md new file mode 100644 index 0000000..a2c89a4 --- /dev/null +++ b/exercise3/problem10/README.md @@ -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" +``` \ No newline at end of file diff --git a/exercise3/problem10/index.js b/exercise3/problem10/index.js new file mode 100644 index 0000000..26de10d --- /dev/null +++ b/exercise3/problem10/index.js @@ -0,0 +1,5 @@ +function move() { + // Your code +} + +export default move; diff --git a/exercise3/problem10/index.test.js b/exercise3/problem10/index.test.js new file mode 100644 index 0000000..6aa3b15 --- /dev/null +++ b/exercise3/problem10/index.test.js @@ -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); + }); +}); diff --git a/exercise3/problem2/README.md b/exercise3/problem2/README.md new file mode 100644 index 0000000..29d59b6 --- /dev/null +++ b/exercise3/problem2/README.md @@ -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 +``` \ No newline at end of file diff --git a/exercise3/problem2/index.js b/exercise3/problem2/index.js new file mode 100644 index 0000000..2996958 --- /dev/null +++ b/exercise3/problem2/index.js @@ -0,0 +1,5 @@ +function intWithinBounds() { + // Your code +} + +export default intWithinBounds; diff --git a/exercise3/problem2/index.test.js b/exercise3/problem2/index.test.js new file mode 100644 index 0000000..b7060a4 --- /dev/null +++ b/exercise3/problem2/index.test.js @@ -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); + } + ); +}); diff --git a/exercise3/problem3/README.md b/exercise3/problem3/README.md new file mode 100644 index 0000000..b7727f7 --- /dev/null +++ b/exercise3/problem3/README.md @@ -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 +``` \ No newline at end of file diff --git a/exercise3/problem3/index.js b/exercise3/problem3/index.js new file mode 100644 index 0000000..fcd5d6f --- /dev/null +++ b/exercise3/problem3/index.js @@ -0,0 +1,5 @@ +function pentagonal() { + // Your code +} + +export default pentagonal; diff --git a/exercise3/problem3/index.test.js b/exercise3/problem3/index.test.js new file mode 100644 index 0000000..b3de206 --- /dev/null +++ b/exercise3/problem3/index.test.js @@ -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); + }); +}); diff --git a/exercise3/problem3/pentagonal_number.png b/exercise3/problem3/pentagonal_number.png new file mode 100644 index 0000000..6872849 Binary files /dev/null and b/exercise3/problem3/pentagonal_number.png differ diff --git a/exercise3/problem4/README.md b/exercise3/problem4/README.md new file mode 100644 index 0000000..c8fed6e --- /dev/null +++ b/exercise3/problem4/README.md @@ -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" +``` \ No newline at end of file diff --git a/exercise3/problem4/index.js b/exercise3/problem4/index.js new file mode 100644 index 0000000..217ae18 --- /dev/null +++ b/exercise3/problem4/index.js @@ -0,0 +1,5 @@ +function makeTitleCase() { + // Your code +} + +export default makeTitleCase; diff --git a/exercise3/problem4/index.test.js b/exercise3/problem4/index.test.js new file mode 100644 index 0000000..bbb6b14 --- /dev/null +++ b/exercise3/problem4/index.test.js @@ -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); + }); +}); diff --git a/exercise3/problem5/README.md b/exercise3/problem5/README.md new file mode 100644 index 0000000..c614e61 --- /dev/null +++ b/exercise3/problem5/README.md @@ -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 +``` \ No newline at end of file diff --git a/exercise3/problem5/index.js b/exercise3/problem5/index.js new file mode 100644 index 0000000..deba434 --- /dev/null +++ b/exercise3/problem5/index.js @@ -0,0 +1,5 @@ +function removeABC() { + // Your code +} + +export default removeABC; diff --git a/exercise3/problem5/index.test.js b/exercise3/problem5/index.test.js new file mode 100644 index 0000000..f98044e --- /dev/null +++ b/exercise3/problem5/index.test.js @@ -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); + }); +}); diff --git a/exercise3/problem6/README.md b/exercise3/problem6/README.md new file mode 100644 index 0000000..22dd124 --- /dev/null +++ b/exercise3/problem6/README.md @@ -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" +``` \ No newline at end of file diff --git a/exercise3/problem6/index.js b/exercise3/problem6/index.js new file mode 100644 index 0000000..bf1bdfa --- /dev/null +++ b/exercise3/problem6/index.js @@ -0,0 +1,5 @@ +function insertWhitespace() { + // Your code +} + +export default insertWhitespace; diff --git a/exercise3/problem6/index.test.js b/exercise3/problem6/index.test.js new file mode 100644 index 0000000..a275fbc --- /dev/null +++ b/exercise3/problem6/index.test.js @@ -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); + }); +}); diff --git a/exercise3/problem7/README.md b/exercise3/problem7/README.md new file mode 100644 index 0000000..7fe2a1a --- /dev/null +++ b/exercise3/problem7/README.md @@ -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 +``` \ No newline at end of file diff --git a/exercise3/problem7/index.js b/exercise3/problem7/index.js new file mode 100644 index 0000000..474f63b --- /dev/null +++ b/exercise3/problem7/index.js @@ -0,0 +1,5 @@ +function isPrimitve() { + // Your code +} + +export default isPrimitve; diff --git a/exercise3/problem7/index.test.js b/exercise3/problem7/index.test.js new file mode 100644 index 0000000..f46fb55 --- /dev/null +++ b/exercise3/problem7/index.test.js @@ -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); + }); +}); diff --git a/exercise3/problem8/README.md b/exercise3/problem8/README.md new file mode 100644 index 0000000..b9966c6 --- /dev/null +++ b/exercise3/problem8/README.md @@ -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 +``` \ No newline at end of file diff --git a/exercise3/problem8/index.js b/exercise3/problem8/index.js new file mode 100644 index 0000000..9ebda87 --- /dev/null +++ b/exercise3/problem8/index.js @@ -0,0 +1,5 @@ +function longestTime() { + // Your code +} + +export default longestTime; diff --git a/exercise3/problem8/index.test.js b/exercise3/problem8/index.test.js new file mode 100644 index 0000000..3486093 --- /dev/null +++ b/exercise3/problem8/index.test.js @@ -0,0 +1,13 @@ +import {describe, expect, test} +import longestTime from "./index"; + +describe("exercise1 - problem8", () => { + test.each([ + {h: 1, m: 59, s: 3598, expected: 1}, + {h: 2, m: 300, s: 15000, expected: 300}, + {h: 15, m: 955, s: 59400, expected: 59400}, + {h: 1, m: 60, s: 3600, expected: 3600}, + ])(".longestTime($h, $m, $s)", ({h, m, s, expected}) => { + expect(longestTime(h, m, s)).toBe(expected); + }); +}); diff --git a/exercise3/problem9/README.md b/exercise3/problem9/README.md new file mode 100644 index 0000000..cba20c2 --- /dev/null +++ b/exercise3/problem9/README.md @@ -0,0 +1,21 @@ +# Problem 9 + +A number is said to be Disarium if the **sum** of its digits raised to their respective positions is the number itself. + +Create a function that determines whether a number is a Disarium or not. + +```js +console.log(isDisarium(75)) // false +// 7^1 + 5^2 = 7 + 25 = 32 + +console.log(isDisarium(135)) // true +// 1^1 + 3^2 + 5^3 = 1 + 9 + 125 = 135 + +console.log(isDisarium(544)) // false + +console.log(isDisarium(518)) // true + +console.log(isDisarium(8)) // true + +console.log(isDisarium(466)) // false +``` \ No newline at end of file diff --git a/exercise3/problem9/index.js b/exercise3/problem9/index.js new file mode 100644 index 0000000..9ef7dcb --- /dev/null +++ b/exercise3/problem9/index.js @@ -0,0 +1,5 @@ +function isDisarium() { + // Your code +} + +export default isDisarium; diff --git a/exercise3/problem9/index.test.js b/exercise3/problem9/index.test.js new file mode 100644 index 0000000..23d77e1 --- /dev/null +++ b/exercise3/problem9/index.test.js @@ -0,0 +1,21 @@ +import {describe, expect, test} +import isDisarium from "./index"; + +describe("exercise1 - problem9", () => { + test.each([ + {num: 6, expected: true}, + {num: 75, expected: false}, + {num: 135, expected: true}, + {num: 466, expected: false}, + {num: 372, expected: false}, + {num: 175, expected: true}, + {num: 1, expected: true}, + {num: 696, expected: false}, + {num: 876, expected: false}, + {num: 89, expected: true}, + {num: 518, expected: true}, + {num: 598, expected: true}, + ])(".isDisarium($num)", ({num, expected}) => { + expect(isDisarium(num)).toBe(expected); + }); +});