From 3eb7ccbda0a4a01cc02c4345ba1284d133bb3fa1 Mon Sep 17 00:00:00 2001 From: mao-sz <122839503+mao-sz@users.noreply.github.com> Date: Sat, 13 Dec 2025 00:11:26 +0000 Subject: [PATCH] Delete duplicate exercises --- 17_factorial/README.md | 12 ---- 17_factorial/factorial.js | 6 -- 17_factorial/factorial.spec.js | 37 ----------- 17_factorial/solution/factorial-solution.js | 7 -- .../solution/factorial-solution.spec.js | 37 ----------- 18_contains/README.md | 12 ---- 18_contains/contains.js | 6 -- 18_contains/contains.spec.js | 60 ----------------- 18_contains/solution/contains-solution.js | 20 ------ .../solution/contains-solution.spec.js | 60 ----------------- 19_totalIntegers/README.md | 8 --- .../solution/totalIntegers-solution.js | 24 ------- .../solution/totalIntegers-solution.spec.js | 40 ------------ 19_totalIntegers/totalIntegers.js | 6 -- 19_totalIntegers/totalIntegers.spec.js | 50 --------------- 20_permutations/README.md | 11 ---- 20_permutations/permutations.js | 6 -- 20_permutations/permutations.spec.js | 64 ------------------- .../solution/permutations-solution.js | 25 -------- .../solution/permutations-solution.spec.js | 60 ----------------- 21_pascal/README.md | 18 ------ 21_pascal/pascal.js | 6 -- 21_pascal/pascal.spec.js | 31 --------- 21_pascal/solution/pascal-solution.js | 17 ----- 21_pascal/solution/pascal-solution.spec.js | 31 --------- 25 files changed, 654 deletions(-) delete mode 100644 17_factorial/README.md delete mode 100644 17_factorial/factorial.js delete mode 100644 17_factorial/factorial.spec.js delete mode 100644 17_factorial/solution/factorial-solution.js delete mode 100644 17_factorial/solution/factorial-solution.spec.js delete mode 100644 18_contains/README.md delete mode 100644 18_contains/contains.js delete mode 100644 18_contains/contains.spec.js delete mode 100644 18_contains/solution/contains-solution.js delete mode 100644 18_contains/solution/contains-solution.spec.js delete mode 100644 19_totalIntegers/README.md delete mode 100644 19_totalIntegers/solution/totalIntegers-solution.js delete mode 100644 19_totalIntegers/solution/totalIntegers-solution.spec.js delete mode 100644 19_totalIntegers/totalIntegers.js delete mode 100644 19_totalIntegers/totalIntegers.spec.js delete mode 100644 20_permutations/README.md delete mode 100644 20_permutations/permutations.js delete mode 100644 20_permutations/permutations.spec.js delete mode 100644 20_permutations/solution/permutations-solution.js delete mode 100644 20_permutations/solution/permutations-solution.spec.js delete mode 100644 21_pascal/README.md delete mode 100644 21_pascal/pascal.js delete mode 100644 21_pascal/pascal.spec.js delete mode 100644 21_pascal/solution/pascal-solution.js delete mode 100644 21_pascal/solution/pascal-solution.spec.js diff --git a/17_factorial/README.md b/17_factorial/README.md deleted file mode 100644 index 94aaf553170..00000000000 --- a/17_factorial/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# Exercise 17 - Factorial - -Write a recursive [factorial](https://simple.wikipedia.org/wiki/Factorial) function that takes a non-negative integer, and returns the product of all positive integers less than or equal to the input integer. An input of `0` should return `1`. The function should only accept numbers, so `'4'` should not be accepted as it is a string. All invalid inputs should return `undefined`. - -For example: - -```javascript -factorial(5); // 5 * 4 * 3 * 2 * 1, Output: 120 -factorial(0); // Output: 1 -factorial(7.2); // Output: undefined -factorial('4'); // Output: undefined -``` diff --git a/17_factorial/factorial.js b/17_factorial/factorial.js deleted file mode 100644 index a88e4f6e573..00000000000 --- a/17_factorial/factorial.js +++ /dev/null @@ -1,6 +0,0 @@ -const factorial = function() { - -}; - -// Do not edit below this line -module.exports = factorial; \ No newline at end of file diff --git a/17_factorial/factorial.spec.js b/17_factorial/factorial.spec.js deleted file mode 100644 index 4250d5d9500..00000000000 --- a/17_factorial/factorial.spec.js +++ /dev/null @@ -1,37 +0,0 @@ -const factorial = require("./factorial"); - -describe('factorial', () => { - test('4th factorial number is 24', () => { - expect(factorial(4)).toBe(24); - }); - test.skip('6th factorial number is 720', () => { - expect(factorial(6)).toBe(720); - }); - test.skip('10th factorial number is 3628800', () => { - expect(factorial(10)).toBe(3628800); - }); - test.skip('15th factorial number is 1307674368000', () => { - expect(factorial(15)).toBe(1307674368000); - }); - test.skip('25th factorial number is 1.5511210043330986e+25', () => { - expect(factorial(25)).toBe(1.5511210043330986e+25); - }); - test.skip('0th factorial number is 1', () => { - expect(factorial(0)).toBe(1); - }); - test.skip("doesn't accept negatives", () => { - expect(factorial(-25)).toBe(undefined); - }); - test.skip("doesn't accept floats", () => { - expect(factorial(5.4)).toBe(undefined); - }); - test.skip("doesn't accept a number as a string", () => { - expect(factorial('5')).toBe(undefined); - }); - test.skip("doesn't accept strings", () => { - expect(factorial('foo')).toBe(undefined); - }); - test.skip("doesn't accept arrays", () => { - expect(factorial([5])).toBe(undefined); - }); -}); diff --git a/17_factorial/solution/factorial-solution.js b/17_factorial/solution/factorial-solution.js deleted file mode 100644 index f28cc71b445..00000000000 --- a/17_factorial/solution/factorial-solution.js +++ /dev/null @@ -1,7 +0,0 @@ -const factorial = function(n) { - if (!Number.isInteger(n) || n < 0) return; - if (n === 0) return 1; - return n * factorial(n - 1); -}; - -module.exports = factorial; diff --git a/17_factorial/solution/factorial-solution.spec.js b/17_factorial/solution/factorial-solution.spec.js deleted file mode 100644 index 7532f54c990..00000000000 --- a/17_factorial/solution/factorial-solution.spec.js +++ /dev/null @@ -1,37 +0,0 @@ -const factorial = require("./factorial-solution"); - -describe('factorial', () => { - test('4th factorial number is 24', () => { - expect(factorial(4)).toBe(24); - }); - test('6th factorial number is 720', () => { - expect(factorial(6)).toBe(720); - }); - test('10th factorial number is 3628800', () => { - expect(factorial(10)).toBe(3628800); - }); - test('15th factorial number is 1307674368000', () => { - expect(factorial(15)).toBe(1307674368000); - }); - test('25th factorial number is 1.5511210043330986e+25', () => { - expect(factorial(25)).toBe(1.5511210043330986e+25); - }); - test('0th factorial number is 1', () => { - expect(factorial(0)).toBe(1); - }); - test('doesn\'t accept negatives', () => { - expect(factorial(-25)).toBe(undefined); - }); - test('doesn\'t accept floats', () => { - expect(factorial(5.4)).toBe(undefined); - }); - test('doesn\'t accept a number as a string', () => { - expect(factorial('5')).toBe(undefined); - }); - test('doesn\'t accept strings', () => { - expect(factorial('foo')).toBe(undefined); - }); - test('doesn\'t accept arrays', () => { - expect(factorial([5])).toBe(undefined); - }); -}); diff --git a/18_contains/README.md b/18_contains/README.md deleted file mode 100644 index 433dca47581..00000000000 --- a/18_contains/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# Exercise 18 - contains - -Write a function that searches for a value in a nested object. It returns true if the object contains that value. - -Objects are compared by reference. - -Examples: - -```javascript -contains({ foo: "foo" }, "bar") // false -contains({ foo: { bar: "bar" } }, "bar") // true -``` diff --git a/18_contains/contains.js b/18_contains/contains.js deleted file mode 100644 index d5c798c74b7..00000000000 --- a/18_contains/contains.js +++ /dev/null @@ -1,6 +0,0 @@ -const contains = function() { - -}; - -// Do not edit below this line -module.exports = contains; diff --git a/18_contains/contains.spec.js b/18_contains/contains.spec.js deleted file mode 100644 index 5db2eea33d5..00000000000 --- a/18_contains/contains.spec.js +++ /dev/null @@ -1,60 +0,0 @@ -const contains = require("./contains"); - -describe("contains", () => { - const meaningOfLifeArray = [42]; - const object = { - data: { - duplicate: "e", - stuff: { - thing: { - banana: NaN, - moreStuff: { - something: "foo", - answer: meaningOfLifeArray, - }, - }, - }, - info: { - duplicate: "e", - magicNumber: 44, - empty: null, - }, - }, - }; - - test("true if the provided number is a value within the object", () => { - expect(contains(object, 44)).toBe(true); - }); - - test.skip("true if the provided string is a value within the object", () => { - expect(contains(object, "foo")).toBe(true); - }); - - test.skip("does not convert input string into a number when searching for a value within the object", () => { - expect(contains(object, "44")).toBe(false); - }); - - test.skip("false if the provided string is not a value within the object", () => { - expect(contains(object, "bar")).toBe(false); - }); - - test.skip("true if provided string is within the object, even if duplicated", () => { - expect(contains(object, "e")).toBe(true); - }); - - test.skip("true if the object contains the same object by reference", () => { - expect(contains(object, meaningOfLifeArray)).toBe(true); - }); - - test.skip("false if no matching object reference", () => { - expect(contains(object, [42])).toBe(false); - }); - - test.skip("true if NaN is a value within the object", () => { - expect(contains(object, NaN)).toBe(true); - }); - - test.skip("false if the provided value exists and is null", () => { - expect(contains(object, null)).toBe(true); - }); -}); diff --git a/18_contains/solution/contains-solution.js b/18_contains/solution/contains-solution.js deleted file mode 100644 index 13bf75c1f4b..00000000000 --- a/18_contains/solution/contains-solution.js +++ /dev/null @@ -1,20 +0,0 @@ -const contains = function (object, searchValue) { - const values = Object.values(object); - - // NaN === NaN evaluates to false - // Normally, we would have to do an explicit Number.isNaN() check to compare NaN equality - // However, Array.prototype.includes automatically handles this for us - if (values.includes(searchValue)) return true; - - const nestedObjects = values.filter( - // typeof null === 'object' evaluates to true ¯\_(ツ)_/¯ - (value) => typeof value === "object" && value !== null - ); - - return nestedObjects.some((nestedObject) => - contains(nestedObject, searchValue) - ); -}; - -// Do not edit below this line -module.exports = contains; diff --git a/18_contains/solution/contains-solution.spec.js b/18_contains/solution/contains-solution.spec.js deleted file mode 100644 index b9710923316..00000000000 --- a/18_contains/solution/contains-solution.spec.js +++ /dev/null @@ -1,60 +0,0 @@ -const contains = require("./contains-solution"); - -describe("contains", () => { - const meaningOfLifeArray = [42]; - const object = { - data: { - duplicate: "e", - stuff: { - thing: { - banana: NaN, - moreStuff: { - something: "foo", - answer: meaningOfLifeArray, - }, - }, - }, - info: { - duplicate: "e", - magicNumber: 44, - empty: null, - }, - }, - }; - - test("true if the provided number is a value within the object", () => { - expect(contains(object, 44)).toBe(true); - }); - - test("true if the provided string is a value within the object", () => { - expect(contains(object, "foo")).toBe(true); - }); - - test("does not convert input string into a number when searching for a value within the object", () => { - expect(contains(object, "44")).toBe(false); - }); - - test("false if the provided string is not a value within the object", () => { - expect(contains(object, "bar")).toBe(false); - }); - - test("true if provided string is within the object, even if duplicated", () => { - expect(contains(object, "e")).toBe(true); - }); - - test("true if the object contains the same object by reference", () => { - expect(contains(object, meaningOfLifeArray)).toBe(true); - }); - - test("false if no matching object reference", () => { - expect(contains(object, [42])).toBe(false); - }); - - test("true if NaN is a value within the object", () => { - expect(contains(object, NaN)).toBe(true); - }); - - test("true if the provided value exists and is null", () => { - expect(contains(object, null)).toBe(true); - }); -}); diff --git a/19_totalIntegers/README.md b/19_totalIntegers/README.md deleted file mode 100644 index 29c70904b9b..00000000000 --- a/19_totalIntegers/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# Exercise 19 - totalIntegers - -Write a function that takes in an arbitrarily deep array or object and returns the total number of integers stored inside this array or object. - -```javascript -totalIntegers([[[5], 3], 0, 2, ['foo'], [], [4, [5, 6]]]); // returns 7 -totalIntegers({ a: 1, b: { a: [5, 10], b: 11 } }); // returns 4 -``` diff --git a/19_totalIntegers/solution/totalIntegers-solution.js b/19_totalIntegers/solution/totalIntegers-solution.js deleted file mode 100644 index 7ba19766cad..00000000000 --- a/19_totalIntegers/solution/totalIntegers-solution.js +++ /dev/null @@ -1,24 +0,0 @@ -// The extra null check is required since typeof null === "object" evaluates to true -const isObject = (value) => typeof value === 'object' && value !== null; - -const totalIntegers = function (obj) { - let count = 0; - - if (!isObject(obj)) { - return; - } - - const elements = Object.values(obj); - - for (const el of elements) { - if (Number.isInteger(el)) { - count++; - } else if (isObject(el)) { - count += totalIntegers(el); - } - } - return count; -}; - -// Do not edit below this line -module.exports = totalIntegers; diff --git a/19_totalIntegers/solution/totalIntegers-solution.spec.js b/19_totalIntegers/solution/totalIntegers-solution.spec.js deleted file mode 100644 index 19676196061..00000000000 --- a/19_totalIntegers/solution/totalIntegers-solution.spec.js +++ /dev/null @@ -1,40 +0,0 @@ -const totalIntegers = require('./totalIntegers-solution'); - -describe('totalIntegers', () => { - test('Works with a simple array of numbers', () => { - expect(totalIntegers([1, 2, 3])).toBe(3); - }); - test('Ignores non-integer values', () => { - expect(totalIntegers([1, 2, '3', 4])).toBe(3); - }); - test('Works with simple objects', () => { - expect(totalIntegers({ a: 1, b: '2', c: 3 })).toBe(2); - }); - test('Works with an empty nested array', () => { - expect(totalIntegers([[], [], []])).toBe(0); - }); - test('Works with a very nested array', () => { - expect(totalIntegers([[[[[[[[[[[[[[4]]]]]], 246]]]]]]]])).toBe(2); - }); - test('Works with negative numbers', () => { - expect(totalIntegers([5, 7, -7, [45, -1, -0], [4, 7, -4, -4, -4, [777777, -45674]], [-5477654]])).toBe(14); - }); - test('Works with floats', () => { - expect(totalIntegers([5, 7.7, 7, [45, 1, 0], [4.0, 7, [7.77777, 4567.4]], [5477.654]])).toBe(7); - }); - test('Only accepts arrays or objects', () => { - expect(totalIntegers('2')).toBe(undefined); - expect(totalIntegers(() => {})).toBe(undefined); - expect(totalIntegers(42)).toBe(undefined); - expect(totalIntegers(NaN)).toBe(undefined); - }); - test('Works with NaN', () => { - expect(totalIntegers([5, NaN, [NaN, NaN, 64], 4])).toBe(3); - }); - test('Works with a nested array of all kinds of things', () => { - expect(totalIntegers([NaN, [[{}], 555 ], '444', [], 74.0, undefined, [[() => {}], [4], Infinity, [[[], -44.0], [null, '-4'], NaN [[]], 6]], () => {}, [[], [-Infinity, ['4'], [4.7, -46.7], NaN]]])).toBe(5); - }); - test('Works with arrays containing objects containing integers', () => { - expect(totalIntegers([4, 6, { a: 1, b: { a: [5, 10], b: 11 } }, 9])).toBe(7); - }); -}); diff --git a/19_totalIntegers/totalIntegers.js b/19_totalIntegers/totalIntegers.js deleted file mode 100644 index d4c24861530..00000000000 --- a/19_totalIntegers/totalIntegers.js +++ /dev/null @@ -1,6 +0,0 @@ -const totalIntegers = function() { - -}; - -// Do not edit below this line -module.exports = totalIntegers; diff --git a/19_totalIntegers/totalIntegers.spec.js b/19_totalIntegers/totalIntegers.spec.js deleted file mode 100644 index d33d2293d30..00000000000 --- a/19_totalIntegers/totalIntegers.spec.js +++ /dev/null @@ -1,50 +0,0 @@ -const totalIntegers = require('./totalIntegers'); - -describe('totalIntegers', () => { - test('Works with a simple array of numbers', () => { - expect(totalIntegers([1, 2, 3])).toBe(3); - }); - - test.skip('Ignores non-integer values', () => { - expect(totalIntegers([1, 2, '3', 4])).toBe(3); - }); - - test.skip('Works with simple objects', () => { - expect(totalIntegers({ a: 1, b: '2', c: 3 })).toBe(2); - }); - - test.skip('Works with an empty nested array', () => { - expect(totalIntegers([[], [], []])).toBe(0); - }); - - test.skip('Works with a very nested array', () => { - expect(totalIntegers([[[[[[[[[[[[[[4]]]]]], 246]]]]]]]])).toBe(2); - }); - - test.skip('Works with negative numbers', () => { - expect(totalIntegers([5, 7, -7, [45, -1, -0], [4, 7, -4, -4, -4, [777777, -45674]], [-5477654]])).toBe(14); - }); - - test.skip('Works with floats', () => { - expect(totalIntegers([5, 7.7, 7, [45, 1, 0], [4.0, 7, [7.77777, 4567.4]], [5477.654]])).toBe(7); - }); - - test.skip('Only accepts arrays or objects', () => { - expect(totalIntegers('2')).toBe(undefined); - expect(totalIntegers(() => {})).toBe(undefined); - expect(totalIntegers(42)).toBe(undefined); - expect(totalIntegers(NaN)).toBe(undefined); - }); - - test.skip('Works with NaN', () => { - expect(totalIntegers([5, NaN, [NaN, NaN, 64], 4])).toBe(3); - }); - - test.skip('Works with a nested array of all kinds of things', () => { - expect(totalIntegers([NaN, [[{}], 555 ], '444', [], 74.0, undefined, [[() => {}], [4], Infinity, [[[], -44.0], [null, '-4'], NaN [[]], 6]], () => {}, [[], [-Infinity, ['4'], [4.7, -46.7], NaN]]])).toBe(5); - }); - - test.skip('Works with arrays containing objects containing integers', () => { - expect(totalIntegers([4, 6, { a: 1, b: { a: [5, 10], b: 11 } }, 9])).toBe(7); - }); -}); diff --git a/20_permutations/README.md b/20_permutations/README.md deleted file mode 100644 index ef4df4401d0..00000000000 --- a/20_permutations/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# Exercise 20 - permutations - -Write a function that takes in an empty array or an input array of an consecutive positive integers, starting at 1, and returns an array of all possible permutations of the original array - -The integers will not repeat. - -```javascript -permutations([1, 2, 3]); // [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] -// An empty set has a single permutation, 0! = 1 -permutations([]); // [[]] -``` diff --git a/20_permutations/permutations.js b/20_permutations/permutations.js deleted file mode 100644 index c7380ec3640..00000000000 --- a/20_permutations/permutations.js +++ /dev/null @@ -1,6 +0,0 @@ -const permutations = function() { - -}; - -// Do not edit below this line -module.exports = permutations; diff --git a/20_permutations/permutations.spec.js b/20_permutations/permutations.spec.js deleted file mode 100644 index 69ee0a1ae9b..00000000000 --- a/20_permutations/permutations.spec.js +++ /dev/null @@ -1,64 +0,0 @@ -const permutations = require("./permutations"); - -describe("permutations", () => { - test("1 possible permutation for a set containing 0 numbers", () => { - expect(permutations([])).toEqual([[]]); - }); - - test.skip("1 possible permutation for a set containing 1 number", () => { - expect(permutations([1])).toEqual([[1]]); - }); - - test.skip("2 possible permutations for a set containing 2 numbers", () => { - expect(permutations([1, 2]).sort()).toEqual( - [ - [1, 2], - [2, 1], - ].sort(), - ); - }); - - test.skip("6 possible permutations for a set containing 3 numbers", () => { - expect(permutations([1, 2, 3]).sort()).toEqual( - [ - [1, 2, 3], - [1, 3, 2], - [2, 1, 3], - [2, 3, 1], - [3, 1, 2], - [3, 2, 1], - ].sort(), - ); - }); - - test.skip("24 possible permutations for a set containing 4 numbers", () => { - expect(permutations([1, 2, 3, 4]).sort()).toEqual( - [ - [1, 2, 3, 4], - [1, 2, 4, 3], - [1, 3, 2, 4], - [1, 3, 4, 2], - [1, 4, 2, 3], - [1, 4, 3, 2], - [2, 1, 3, 4], - [2, 1, 4, 3], - [2, 3, 1, 4], - [2, 3, 4, 1], - [2, 4, 1, 3], - [2, 4, 3, 1], - [3, 1, 2, 4], - [3, 1, 4, 2], - [3, 2, 1, 4], - [3, 2, 4, 1], - [3, 4, 1, 2], - [3, 4, 2, 1], - [4, 1, 2, 3], - [4, 1, 3, 2], - [4, 2, 1, 3], - [4, 2, 3, 1], - [4, 3, 1, 2], - [4, 3, 2, 1], - ].sort(), - ); - }); -}); diff --git a/20_permutations/solution/permutations-solution.js b/20_permutations/solution/permutations-solution.js deleted file mode 100644 index fb3f2d5cf79..00000000000 --- a/20_permutations/solution/permutations-solution.js +++ /dev/null @@ -1,25 +0,0 @@ -const permutations = function (array, index = 0, results = []) { - if (index == array.length) { - // We have formed a valid permutation. - - // the [...array] syntax is a way to clone the contents of the array. - // because we do not want to pass a reference to the array, as that would mean - // that each item in `results` will be the same item - results.push([...array]); - return results; - } - - for (let i = index; i < array.length; i++) { - // We use "destructuring assignment" here to swap the values of array[index] and array[i] - // - // More info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment - [array[index], array[i]] = [array[i], array[index]]; - permutations(array, index + 1, results); - [array[index], array[i]] = [array[i], array[index]]; - } - - return results; -}; - -// Do not edit below this line -module.exports = permutations; diff --git a/20_permutations/solution/permutations-solution.spec.js b/20_permutations/solution/permutations-solution.spec.js deleted file mode 100644 index 2f3a393f495..00000000000 --- a/20_permutations/solution/permutations-solution.spec.js +++ /dev/null @@ -1,60 +0,0 @@ -const permutations = require("./permutations-solution"); - -describe("permutations", () => { - test("1 possible permutation for a set containing 0 numbers", () => { - expect(permutations([])).toEqual([[]]); - }); - test("1 possible permutation for a set containing 1 number", () => { - expect(permutations([1])).toEqual([[1]]); - }); - test("2 possible permutations for a set containing 2 numbers", () => { - expect(permutations([1, 2]).sort()).toEqual( - [ - [1, 2], - [2, 1], - ].sort(), - ); - }); - test("6 possible permutations for a set containing 3 numbers", () => { - expect(permutations([1, 2, 3]).sort()).toEqual( - [ - [1, 2, 3], - [1, 3, 2], - [2, 1, 3], - [2, 3, 1], - [3, 1, 2], - [3, 2, 1], - ].sort(), - ); - }); - test("24 possible permutations for a set containing 4 numbers", () => { - expect(permutations([1, 2, 3, 4]).sort()).toEqual( - [ - [1, 2, 3, 4], - [1, 2, 4, 3], - [1, 3, 2, 4], - [1, 3, 4, 2], - [1, 4, 2, 3], - [1, 4, 3, 2], - [2, 1, 3, 4], - [2, 1, 4, 3], - [2, 3, 1, 4], - [2, 3, 4, 1], - [2, 4, 1, 3], - [2, 4, 3, 1], - [3, 1, 2, 4], - [3, 1, 4, 2], - [3, 2, 1, 4], - [3, 2, 4, 1], - [3, 4, 1, 2], - [3, 4, 2, 1], - [4, 1, 2, 3], - [4, 1, 3, 2], - [4, 2, 1, 3], - [4, 2, 3, 1], - [4, 3, 1, 2], - [4, 3, 2, 1], - ].sort(), - ); - }); -}); diff --git a/21_pascal/README.md b/21_pascal/README.md deleted file mode 100644 index ec3614c1334..00000000000 --- a/21_pascal/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# Exercise 21 - pascal - -The pascal's triangle is modelled as follows: -- The first row is `1`. -- Each row can be considered to have a hidden `0` to either sides of it. So the first row could also be said to be `0, 1, 0` -- To obtain the next row, we take each number and add it with its rightmost neighbor. - -First row: `[1]` -Second row: `[0+1, 1+0]` or simply `[1, 1]` -Third row: `[0+1, 1+1, 1+0]` or simply `[1, 2, 1]` -Fourth row: `[0+1, 1+2, 2+1, 1+0]` or simply `[1, 3, 3, 1]` -... - -The pattern continues forever. - -Your task is to create a *recursive* function, `pascal` - that will take an input `n` and output the `n`th pascal's row as an array of numbers. - -For example, `pascal(3)` should return `[1, 2, 1]`. diff --git a/21_pascal/pascal.js b/21_pascal/pascal.js deleted file mode 100644 index 74d6a382f7a..00000000000 --- a/21_pascal/pascal.js +++ /dev/null @@ -1,6 +0,0 @@ -const pascal = function() { - -}; - -// Do not edit below this line -module.exports = pascal; diff --git a/21_pascal/pascal.spec.js b/21_pascal/pascal.spec.js deleted file mode 100644 index d376f56bdee..00000000000 --- a/21_pascal/pascal.spec.js +++ /dev/null @@ -1,31 +0,0 @@ -const pascal = require('./pascal'); - -describe('pascal', () => { - test('Gets the first row of pascal', () => { - expect(pascal(1)).toEqual([1]); - }); - - test.skip('Gets the second row of pascal', () => { - expect(pascal(2)).toEqual([1, 1]); - }); - - test.skip('Gets the third row of pascal', () => { - expect(pascal(3)).toEqual([1, 2, 1]); - }); - - test.skip('Gets the fourth row of pascal', () => { - expect(pascal(4)).toEqual([1, 3, 3, 1]); - }); - - test.skip('Gets the fifth row of pascal', () => { - expect(pascal(5)).toEqual([1, 4, 6, 4, 1]); - }); - - test.skip('Gets the sixth row of pascal', () => { - expect(pascal(6)).toEqual([1, 5, 10, 10, 5, 1]); - }); - - test.skip('Gets the seventh row of pascal', () => { - expect(pascal(7)).toEqual([1, 6, 15, 20, 15, 6, 1]); - }); -}); diff --git a/21_pascal/solution/pascal-solution.js b/21_pascal/solution/pascal-solution.js deleted file mode 100644 index b70cee732bc..00000000000 --- a/21_pascal/solution/pascal-solution.js +++ /dev/null @@ -1,17 +0,0 @@ -const pascal = function (counter) { - const currentLine = [1]; - if (counter === 1) { - return currentLine; - } - - const previousLine = pascal(counter - 1); - previousLine.forEach((number, i) => { - const rightNeighbor = previousLine[i + 1] ?? 0; - currentLine.push(number + rightNeighbor); - }) - - return currentLine; -} - -// Do not edit below this line -module.exports = pascal; diff --git a/21_pascal/solution/pascal-solution.spec.js b/21_pascal/solution/pascal-solution.spec.js deleted file mode 100644 index 41e072ddde1..00000000000 --- a/21_pascal/solution/pascal-solution.spec.js +++ /dev/null @@ -1,31 +0,0 @@ -const pascal = require('./pascal-solution'); - -describe('pascal', () => { - test('Gets the first row of pascal', () => { - expect(pascal(1)).toEqual([1]); - }); - - test('Gets the second row of pascal', () => { - expect(pascal(2)).toEqual([1, 1]); - }); - - test('Gets the third row of pascal', () => { - expect(pascal(3)).toEqual([1, 2, 1]); - }); - - test('Gets the fourth row of pascal', () => { - expect(pascal(4)).toEqual([1, 3, 3, 1]); - }); - - test('Gets the fifth row of pascal', () => { - expect(pascal(5)).toEqual([1, 4, 6, 4, 1]); - }); - - test('Gets the sixth row of pascal', () => { - expect(pascal(6)).toEqual([1, 5, 10, 10, 5, 1]); - }); - - test('Gets the seventh row of pascal', () => { - expect(pascal(7)).toEqual([1, 6, 15, 20, 15, 6, 1]); - }); -});