From fb1a2db8d734e813dad8ede3783ea6c290239083 Mon Sep 17 00:00:00 2001 From: thatblindgeye Date: Sun, 20 Feb 2022 14:07:44 -0500 Subject: [PATCH 1/7] Add solution directories for exercises --- 01_helloWorld/solution/helloWorld-solution.js | 5 ++ .../solution/helloWorld-solution.spec.js | 7 ++ .../solution/repeatString-solution.js | 10 +++ .../solution/repeatString-solution.spec.js | 41 ++++++++++ .../solution/reverseString-solution.js | 5 ++ .../solution/reverseString-solution.spec.js | 18 +++++ .../solution/removeFromArray-solution.js | 31 ++++++++ .../solution/removeFromArray-solution.spec.js | 28 +++++++ 05_sumAll/solution/sumAll-solution.js | 16 ++++ 05_sumAll/solution/sumAll-solution.spec.js | 22 ++++++ 06_leapYears/solution/leapYears-solution.js | 5 ++ .../solution/leapYears-solution.spec.js | 22 ++++++ .../solution/tempConversion-solution.js | 12 +++ .../solution/tempConversion-solution.spec.js | 25 ++++++ 08_calculator/solution/calculator-solution.js | 48 ++++++++++++ .../solution/calculator-solution.spec.js | 77 +++++++++++++++++++ .../solution/palindromes-solution.js | 6 ++ .../solution/palindromes-solution.spec.js | 24 ++++++ 10_fibonacci/solution/fibonacci-solution.js | 14 ++++ .../solution/fibonacci-solution.spec.js | 31 ++++++++ .../solution/getTheTitles-solution.js | 5 ++ .../solution/getTheTitles-solution.spec.js | 18 +++++ .../solution/findTheOldest-solution.js | 19 +++++ .../solution/findTheOldest-solution.spec.js | 62 +++++++++++++++ 13_caesar/solution/caesar-solution.js | 26 +++++++ 13_caesar/solution/caesar-solution.spec.js | 23 ++++++ 26 files changed, 600 insertions(+) create mode 100644 01_helloWorld/solution/helloWorld-solution.js create mode 100644 01_helloWorld/solution/helloWorld-solution.spec.js create mode 100644 02_repeatString/solution/repeatString-solution.js create mode 100644 02_repeatString/solution/repeatString-solution.spec.js create mode 100644 03_reverseString/solution/reverseString-solution.js create mode 100644 03_reverseString/solution/reverseString-solution.spec.js create mode 100644 04_removeFromArray/solution/removeFromArray-solution.js create mode 100644 04_removeFromArray/solution/removeFromArray-solution.spec.js create mode 100644 05_sumAll/solution/sumAll-solution.js create mode 100644 05_sumAll/solution/sumAll-solution.spec.js create mode 100644 06_leapYears/solution/leapYears-solution.js create mode 100644 06_leapYears/solution/leapYears-solution.spec.js create mode 100644 07_tempConversion/solution/tempConversion-solution.js create mode 100644 07_tempConversion/solution/tempConversion-solution.spec.js create mode 100644 08_calculator/solution/calculator-solution.js create mode 100644 08_calculator/solution/calculator-solution.spec.js create mode 100644 09_palindromes/solution/palindromes-solution.js create mode 100644 09_palindromes/solution/palindromes-solution.spec.js create mode 100644 10_fibonacci/solution/fibonacci-solution.js create mode 100644 10_fibonacci/solution/fibonacci-solution.spec.js create mode 100644 11_getTheTitles/solution/getTheTitles-solution.js create mode 100644 11_getTheTitles/solution/getTheTitles-solution.spec.js create mode 100644 12_findTheOldest/solution/findTheOldest-solution.js create mode 100644 12_findTheOldest/solution/findTheOldest-solution.spec.js create mode 100644 13_caesar/solution/caesar-solution.js create mode 100644 13_caesar/solution/caesar-solution.spec.js diff --git a/01_helloWorld/solution/helloWorld-solution.js b/01_helloWorld/solution/helloWorld-solution.js new file mode 100644 index 0000000..002f305 --- /dev/null +++ b/01_helloWorld/solution/helloWorld-solution.js @@ -0,0 +1,5 @@ +const helloWorld = function () { + return 'Hello, World!'; +}; + +module.exports = helloWorld; diff --git a/01_helloWorld/solution/helloWorld-solution.spec.js b/01_helloWorld/solution/helloWorld-solution.spec.js new file mode 100644 index 0000000..364645d --- /dev/null +++ b/01_helloWorld/solution/helloWorld-solution.spec.js @@ -0,0 +1,7 @@ +const helloWorld = require('./helloWorld-solution'); + +describe('Hello World', function () { + test('says "Hello, World!"', function () { + expect(helloWorld()).toEqual('Hello, World!'); + }); +}); diff --git a/02_repeatString/solution/repeatString-solution.js b/02_repeatString/solution/repeatString-solution.js new file mode 100644 index 0000000..e8ea93e --- /dev/null +++ b/02_repeatString/solution/repeatString-solution.js @@ -0,0 +1,10 @@ +const repeatString = function (word, times) { + if (times < 0) return 'ERROR'; + let string = ''; + for (let i = 0; i < times; i++) { + string += word; + } + return string; +}; + +module.exports = repeatString; diff --git a/02_repeatString/solution/repeatString-solution.spec.js b/02_repeatString/solution/repeatString-solution.spec.js new file mode 100644 index 0000000..299874b --- /dev/null +++ b/02_repeatString/solution/repeatString-solution.spec.js @@ -0,0 +1,41 @@ +const repeatString = require('./repeatString-solution'); + +describe('repeatString', () => { + test('repeats the string', () => { + expect(repeatString('hey', 3)).toEqual('heyheyhey'); + }); + test.skip('repeats the string many times', () => { + expect(repeatString('hey', 10)).toEqual( + 'heyheyheyheyheyheyheyheyheyhey' + ); + }); + test.skip('repeats the string 1 times', () => { + expect(repeatString('hey', 1)).toEqual('hey'); + }); + test.skip('repeats the string 0 times', () => { + expect(repeatString('hey', 0)).toEqual(''); + }); + test.skip('returns ERROR with negative numbers', () => { + expect(repeatString('hey', -1)).toEqual('ERROR'); + }); + test.skip('repeats the string a random amount of times', function () { + /*The number is generated by using Math.random to get a value from between + 0 to 1, when this is multiplied by 1000 and rounded down with Math.floor it + equals a number between 0 to 999 (this number will change everytime you run + the test).*/ + + // DO NOT use Math.floor(Math.random() * 1000) in your code, + // this test generates a random number, then passes it into your code with a function parameter. + // If this doesn't make sense, you should go read about functions here: https://www.theodinproject.com/paths/foundations/courses/foundations/lessons/fundamentals-part-3 + const number = Math.floor(Math.random() * 1000); + /*The .match(/((hey))/g).length is a regex that will count the number of heys + in the result, which if your function works correctly will equal the number that + was randomaly generated. */ + expect(repeatString('hey', number).match(/((hey))/g).length).toEqual( + number + ); + }); + test.skip('works with blank strings', () => { + expect(repeatString('', 10)).toEqual(''); + }); +}); diff --git a/03_reverseString/solution/reverseString-solution.js b/03_reverseString/solution/reverseString-solution.js new file mode 100644 index 0000000..7aee226 --- /dev/null +++ b/03_reverseString/solution/reverseString-solution.js @@ -0,0 +1,5 @@ +const reverseString = function (string) { + return string.split('').reverse().join(''); +}; + +module.exports = reverseString; diff --git a/03_reverseString/solution/reverseString-solution.spec.js b/03_reverseString/solution/reverseString-solution.spec.js new file mode 100644 index 0000000..94b2624 --- /dev/null +++ b/03_reverseString/solution/reverseString-solution.spec.js @@ -0,0 +1,18 @@ +const reverseString = require('./reverseString-solution'); + +describe('reverseString', () => { + test('reverses single word', () => { + expect(reverseString('hello')).toEqual('olleh'); + }); + + test.skip('reverses multiple words', () => { + expect(reverseString('hello there')).toEqual('ereht olleh'); + }); + + test.skip('works with numbers and punctuation', () => { + expect(reverseString('123! abc!')).toEqual('!cba !321'); + }); + test.skip('works with blank strings', () => { + expect(reverseString('')).toEqual(''); + }); +}); diff --git a/04_removeFromArray/solution/removeFromArray-solution.js b/04_removeFromArray/solution/removeFromArray-solution.js new file mode 100644 index 0000000..7399ed8 --- /dev/null +++ b/04_removeFromArray/solution/removeFromArray-solution.js @@ -0,0 +1,31 @@ +// we have 2 solutions here, an easier one and a more advanced one. +// The easiest way to get an array of all of the arguments that are passed to a function +// is using the rest operator. If this is unfamiliar to you look it up! +const removeFromArray = function (...args) { + // the very first item in our list of arguments is the array, we pull it out with args[0] + const array = args[0]; + // create a new empty array + const newArray = []; + // use forEach to go through the array + array.forEach((item) => { + // push every element into the new array + // UNLESS it is included in the function arguments + // so we create a new array with every item, except those that should be removed + if (!args.includes(item)) { + newArray.push(item); + } + }); + // and return that array + return newArray; +}; + +// A simpler, but more advanced way to do it is to use the 'filter' function, +// which basically does what we did with the forEach above. + +// var removeFromArray = function(...args) { +// const array = args[0] +// return array.filter(val => !args.includes(val)) +// } +// + +module.exports = removeFromArray; diff --git a/04_removeFromArray/solution/removeFromArray-solution.spec.js b/04_removeFromArray/solution/removeFromArray-solution.spec.js new file mode 100644 index 0000000..bc1eb1a --- /dev/null +++ b/04_removeFromArray/solution/removeFromArray-solution.spec.js @@ -0,0 +1,28 @@ +const removeFromArray = require('./removeFromArray-solution'); + +describe('removeFromArray', () => { + test('removes a single value', () => { + expect(removeFromArray([1, 2, 3, 4], 3)).toEqual([1, 2, 4]); + }); + test.skip('removes multiple values', () => { + expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]); + }); + test.skip('ignores non present values', () => { + expect(removeFromArray([1, 2, 3, 4], 7, 'tacos')).toEqual([1, 2, 3, 4]); + }); + test.skip('ignores non present values, but still works', () => { + expect(removeFromArray([1, 2, 3, 4], 7, 2)).toEqual([1, 3, 4]); + }); + test.skip('can remove all values', () => { + expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toEqual([]); + }); + test.skip('works with strings', () => { + expect(removeFromArray(['hey', 2, 3, 'ho'], 'hey', 3)).toEqual([ + 2, + 'ho', + ]); + }); + test.skip('only removes same type', () => { + expect(removeFromArray([1, 2, 3], '1', 3)).toEqual([1, 2]); + }); +}); diff --git a/05_sumAll/solution/sumAll-solution.js b/05_sumAll/solution/sumAll-solution.js new file mode 100644 index 0000000..9d95b64 --- /dev/null +++ b/05_sumAll/solution/sumAll-solution.js @@ -0,0 +1,16 @@ +const sumAll = function (min, max) { + if (!Number.isInteger(min) || !Number.isInteger(max)) return 'ERROR'; + if (min < 0 || max < 0) return 'ERROR'; + if (min > max) { + const temp = min; + min = max; + max = temp; + } + let sum = 0; + for (let i = min; i < max + 1; i++) { + sum += i; + } + return sum; +}; + +module.exports = sumAll; diff --git a/05_sumAll/solution/sumAll-solution.spec.js b/05_sumAll/solution/sumAll-solution.spec.js new file mode 100644 index 0000000..ba30f62 --- /dev/null +++ b/05_sumAll/solution/sumAll-solution.spec.js @@ -0,0 +1,22 @@ +const sumAll = require('./sumAll-solution'); + +describe('sumAll', () => { + test('sums numbers within the range', () => { + expect(sumAll(1, 4)).toEqual(10); + }); + test.skip('works with large numbers', () => { + expect(sumAll(1, 4000)).toEqual(8002000); + }); + test.skip('works with larger number first', () => { + expect(sumAll(123, 1)).toEqual(7626); + }); + test.skip('returns ERROR with negative numbers', () => { + expect(sumAll(-10, 4)).toEqual('ERROR'); + }); + test.skip('returns ERROR with non-number parameters', () => { + expect(sumAll(10, '90')).toEqual('ERROR'); + }); + test.skip('returns ERROR with non-number parameters', () => { + expect(sumAll(10, [90, 1])).toEqual('ERROR'); + }); +}); diff --git a/06_leapYears/solution/leapYears-solution.js b/06_leapYears/solution/leapYears-solution.js new file mode 100644 index 0000000..31898b7 --- /dev/null +++ b/06_leapYears/solution/leapYears-solution.js @@ -0,0 +1,5 @@ +const leapYears = function (year) { + return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0); +}; + +module.exports = leapYears; diff --git a/06_leapYears/solution/leapYears-solution.spec.js b/06_leapYears/solution/leapYears-solution.spec.js new file mode 100644 index 0000000..bcc422c --- /dev/null +++ b/06_leapYears/solution/leapYears-solution.spec.js @@ -0,0 +1,22 @@ +const leapYears = require('./leapYears-solution'); + +describe('leapYears', () => { + test('works with non century years', () => { + expect(leapYears(1996)).toBe(true); + }); + test.skip('works with non century years', () => { + expect(leapYears(1997)).toBe(false); + }); + test.skip('works with ridiculously futuristic non century years', () => { + expect(leapYears(34992)).toBe(true); + }); + test.skip('works with century years', () => { + expect(leapYears(1900)).toBe(false); + }); + test.skip('works with century years', () => { + expect(leapYears(1600)).toBe(true); + }); + test.skip('works with century years', () => { + expect(leapYears(700)).toBe(false); + }); +}); diff --git a/07_tempConversion/solution/tempConversion-solution.js b/07_tempConversion/solution/tempConversion-solution.js new file mode 100644 index 0000000..a5fad55 --- /dev/null +++ b/07_tempConversion/solution/tempConversion-solution.js @@ -0,0 +1,12 @@ +const ftoc = function (f) { + return Math.round((f - 32) * (5 / 9) * 10) / 10; +}; + +const ctof = function (c) { + return Math.round(((c * 9) / 5 + 32) * 10) / 10; +}; + +module.exports = { + ftoc, + ctof, +}; diff --git a/07_tempConversion/solution/tempConversion-solution.spec.js b/07_tempConversion/solution/tempConversion-solution.spec.js new file mode 100644 index 0000000..001351d --- /dev/null +++ b/07_tempConversion/solution/tempConversion-solution.spec.js @@ -0,0 +1,25 @@ +const { ftoc, ctof } = require('./tempConversion-solution'); + +describe('ftoc', () => { + test('works', () => { + expect(ftoc(32)).toEqual(0); + }); + test.skip('rounds to 1 decimal', () => { + expect(ftoc(100)).toEqual(37.8); + }); + test.skip('works with negatives', () => { + expect(ftoc(-100)).toEqual(-73.3); + }); +}); + +describe('ctof', () => { + test.skip('works', () => { + expect(ctof(0)).toEqual(32); + }); + test.skip('rounds to 1 decimal', () => { + expect(ctof(73.2)).toEqual(163.8); + }); + test.skip('works with negatives', () => { + expect(ctof(-10)).toEqual(14); + }); +}); diff --git a/08_calculator/solution/calculator-solution.js b/08_calculator/solution/calculator-solution.js new file mode 100644 index 0000000..ea9874a --- /dev/null +++ b/08_calculator/solution/calculator-solution.js @@ -0,0 +1,48 @@ +const add = function (a, b) { + return a + b; +}; + +const subtract = function (a, b) { + return a - b; +}; + +const sum = function (array) { + return array.reduce((total, current) => total + current, 0); +}; + +const multiply = function (array) { + return array.length + ? array.reduce((accumulator, nextItem) => accumulator * nextItem) + : 0; +}; + +const power = function (a, b) { + return Math.pow(a, b); +}; + +const factorial = function (n) { + if (n === 0) return 1; + let product = 1; + for (let i = n; i > 0; i--) { + product *= i; + } + return product; +}; + +// This is another implementation of Factorial that uses recursion +// THANKS to @ThirtyThreeB! +const recursiveFactorial = function (n) { + if (n === 0) { + return 1; + } + return n * recursiveFactorial(n - 1); +}; + +module.exports = { + add, + subtract, + sum, + multiply, + power, + factorial, +}; diff --git a/08_calculator/solution/calculator-solution.spec.js b/08_calculator/solution/calculator-solution.spec.js new file mode 100644 index 0000000..3356e00 --- /dev/null +++ b/08_calculator/solution/calculator-solution.spec.js @@ -0,0 +1,77 @@ +const calculator = require('./calculator-solution'); + +describe('add', () => { + test('adds 0 and 0', () => { + expect(calculator.add(0, 0)).toBe(0); + }); + + test.skip('adds 2 and 2', () => { + expect(calculator.add(2, 2)).toBe(4); + }); + + test.skip('adds positive numbers', () => { + expect(calculator.add(2, 6)).toBe(8); + }); +}); + +describe('subtract', () => { + test.skip('subtracts numbers', () => { + expect(calculator.subtract(10, 4)).toBe(6); + }); +}); + +describe('sum', () => { + test.skip('computes the sum of an empty array', () => { + expect(calculator.sum([])).toBe(0); + }); + + test.skip('computes the sum of an array of one number', () => { + expect(calculator.sum([7])).toBe(7); + }); + + test.skip('computes the sum of an array of two numbers', () => { + expect(calculator.sum([7, 11])).toBe(18); + }); + + test.skip('computes the sum of an array of many numbers', () => { + expect(calculator.sum([1, 3, 5, 7, 9])).toBe(25); + }); +}); + +describe('multiply', () => { + test.skip('multiplies two numbers', () => { + expect(calculator.multiply([2, 4])).toBe(8); + }); + + test.skip('multiplies several numbers', () => { + expect(calculator.multiply([2, 4, 6, 8, 10, 12, 14])).toBe(645120); + }); +}); + +describe('power', () => { + test.skip('raises one number to the power of another number', () => { + expect(calculator.power(4, 3)).toBe(64); // 4 to third power is 64 + }); +}); + +describe('factorial', () => { + test.skip('computes the factorial of 0', () => { + expect(calculator.factorial(0)).toBe(1); // 0! = 1 + }); + + test.skip('computes the factorial of 1', () => { + expect(calculator.factorial(1)).toBe(1); + }); + + test.skip('computes the factorial of 2', () => { + expect(calculator.factorial(2)).toBe(2); + }); + + test.skip('computes the factorial of 5', () => { + expect(calculator.factorial(5)).toBe(120); + }); + + test.skip('computes the factorial of 10', () => { + expect(calculator.factorial(10)).toBe(3628800); + }); +}); diff --git a/09_palindromes/solution/palindromes-solution.js b/09_palindromes/solution/palindromes-solution.js new file mode 100644 index 0000000..ffd5dbf --- /dev/null +++ b/09_palindromes/solution/palindromes-solution.js @@ -0,0 +1,6 @@ +const palindromes = function (string) { + processedString = string.toLowerCase().replace(/[^a-z]/g, ''); + return processedString.split('').reverse().join('') == processedString; +}; + +module.exports = palindromes; diff --git a/09_palindromes/solution/palindromes-solution.spec.js b/09_palindromes/solution/palindromes-solution.spec.js new file mode 100644 index 0000000..afcb47a --- /dev/null +++ b/09_palindromes/solution/palindromes-solution.spec.js @@ -0,0 +1,24 @@ +const palindromes = require('./palindromes-solution'); + +describe('palindromes', () => { + test('works with single words', () => { + expect(palindromes('racecar')).toBe(true); + }); + test.skip('works with punctuation ', () => { + expect(palindromes('racecar!')).toBe(true); + }); + test.skip('works with upper-case letters ', () => { + expect(palindromes('Racecar!')).toBe(true); + }); + test.skip('works with multiple words', () => { + expect(palindromes('A car, a man, a maraca.')).toBe(true); + }); + test.skip('works with multiple words', () => { + expect( + palindromes('Animal loots foliated detail of stool lamina.') + ).toBe(true); + }); + test.skip("doesn't just always return true", () => { + expect(palindromes('ZZZZ car, a man, a maraca.')).toBe(false); + }); +}); diff --git a/10_fibonacci/solution/fibonacci-solution.js b/10_fibonacci/solution/fibonacci-solution.js new file mode 100644 index 0000000..9f9a523 --- /dev/null +++ b/10_fibonacci/solution/fibonacci-solution.js @@ -0,0 +1,14 @@ +const fibonacci = function (count) { + if (count < 0) return 'OOPS'; + if (count === 0) return 0; + let a = 0; + let b = 1; + for (let i = 1; i < count; i++) { + const temp = b; + b = a + b; + a = temp; + } + return b; +}; + +module.exports = fibonacci; diff --git a/10_fibonacci/solution/fibonacci-solution.spec.js b/10_fibonacci/solution/fibonacci-solution.spec.js new file mode 100644 index 0000000..997f30d --- /dev/null +++ b/10_fibonacci/solution/fibonacci-solution.spec.js @@ -0,0 +1,31 @@ +const fibonacci = require('./fibonacci-solution'); + +describe('fibonacci', () => { + test('4th fibonacci number is 3', () => { + expect(fibonacci(4)).toBe(3); + }); + test.skip('6th fibonacci number is 8', () => { + expect(fibonacci(6)).toBe(8); + }); + test.skip('10th fibonacci number is 55', () => { + expect(fibonacci(10)).toBe(55); + }); + test.skip('15th fibonacci number is 610', () => { + expect(fibonacci(15)).toBe(610); + }); + test.skip('25th fibonacci number is 75025', () => { + expect(fibonacci(25)).toBe(75025); + }); + test.skip("doesn't accept negatives", () => { + expect(fibonacci(-25)).toBe('OOPS'); + }); + test.skip('DOES accept strings', () => { + expect(fibonacci('1')).toBe(1); + }); + test.skip('DOES accept strings', () => { + expect(fibonacci('2')).toBe(1); + }); + test.skip('DOES accept strings', () => { + expect(fibonacci('8')).toBe(21); + }); +}); diff --git a/11_getTheTitles/solution/getTheTitles-solution.js b/11_getTheTitles/solution/getTheTitles-solution.js new file mode 100644 index 0000000..ebcf404 --- /dev/null +++ b/11_getTheTitles/solution/getTheTitles-solution.js @@ -0,0 +1,5 @@ +const getTheTitles = function (array) { + return array.map((book) => book.title); +}; + +module.exports = getTheTitles; diff --git a/11_getTheTitles/solution/getTheTitles-solution.spec.js b/11_getTheTitles/solution/getTheTitles-solution.spec.js new file mode 100644 index 0000000..e2dc20d --- /dev/null +++ b/11_getTheTitles/solution/getTheTitles-solution.spec.js @@ -0,0 +1,18 @@ +const getTheTitles = require('./getTheTitles-solution'); + +describe('getTheTitles', () => { + const books = [ + { + title: 'Book', + author: 'Name', + }, + { + title: 'Book2', + author: 'Name2', + }, + ]; + + test('gets titles', () => { + expect(getTheTitles(books)).toEqual(['Book', 'Book2']); + }); +}); diff --git a/12_findTheOldest/solution/findTheOldest-solution.js b/12_findTheOldest/solution/findTheOldest-solution.js new file mode 100644 index 0000000..d25a7ff --- /dev/null +++ b/12_findTheOldest/solution/findTheOldest-solution.js @@ -0,0 +1,19 @@ +const findTheOldest = function (array) { + return array.reduce((oldest, currentPerson) => { + const oldestAge = getAge(oldest.yearOfBirth, oldest.yearOfDeath); + const currentAge = getAge( + currentPerson.yearOfBirth, + currentPerson.yearOfDeath + ); + return oldestAge < currentAge ? currentPerson : oldest; + }); +}; + +const getAge = function (birth, death) { + if (!death) { + death = new Date().getFullYear(); + } + return death - birth; +}; + +module.exports = findTheOldest; diff --git a/12_findTheOldest/solution/findTheOldest-solution.spec.js b/12_findTheOldest/solution/findTheOldest-solution.spec.js new file mode 100644 index 0000000..2a33aff --- /dev/null +++ b/12_findTheOldest/solution/findTheOldest-solution.spec.js @@ -0,0 +1,62 @@ +const findTheOldest = require('./findTheOldest-solution'); + +describe('findTheOldest', () => { + test('finds the oldest person!', () => { + const people = [ + { + name: 'Carly', + yearOfBirth: 1942, + yearOfDeath: 1970, + }, + { + name: 'Ray', + yearOfBirth: 1962, + yearOfDeath: 2011, + }, + { + name: 'Jane', + yearOfBirth: 1912, + yearOfDeath: 1941, + }, + ]; + expect(findTheOldest(people).name).toBe('Ray'); + }); + test.skip('finds the oldest person if someone is still living', () => { + const people = [ + { + name: 'Carly', + yearOfBirth: 2018, + }, + { + name: 'Ray', + yearOfBirth: 1962, + yearOfDeath: 2011, + }, + { + name: 'Jane', + yearOfBirth: 1912, + yearOfDeath: 1941, + }, + ]; + expect(findTheOldest(people).name).toBe('Ray'); + }); + test.skip('finds the oldest person if the OLDEST is still living', () => { + const people = [ + { + name: 'Carly', + yearOfBirth: 1066, + }, + { + name: 'Ray', + yearOfBirth: 1962, + yearOfDeath: 2011, + }, + { + name: 'Jane', + yearOfBirth: 1912, + yearOfDeath: 1941, + }, + ]; + expect(findTheOldest(people).name).toBe('Carly'); + }); +}); diff --git a/13_caesar/solution/caesar-solution.js b/13_caesar/solution/caesar-solution.js new file mode 100644 index 0000000..fed2bdf --- /dev/null +++ b/13_caesar/solution/caesar-solution.js @@ -0,0 +1,26 @@ +const caesar = function (string, shift) { + return string + .split('') + .map((char) => shiftChar(char, shift)) + .join(''); +}; + +const codeSet = (code) => (code < 97 ? 65 : 97); + +// this function is just a fancy way of doing % so that it works with negative numbers +// see this link for details: +// https://stackoverflow.com/questions/4467539/javascript-modulo-gives-a-negative-result-for-negative-numbers +const mod = (n, m) => ((n % m) + m) % m; + +const shiftChar = (char, shift) => { + const code = char.charCodeAt(); + + if ((code >= 65 && code <= 90) || (code >= 97 && code <= 122)) { + return String.fromCharCode( + mod(code + shift - codeSet(code), 26) + codeSet(code) + ); + } + return char; +}; + +module.exports = caesar; diff --git a/13_caesar/solution/caesar-solution.spec.js b/13_caesar/solution/caesar-solution.spec.js new file mode 100644 index 0000000..68902ad --- /dev/null +++ b/13_caesar/solution/caesar-solution.spec.js @@ -0,0 +1,23 @@ +const caesar = require('./caesar-solution'); + +test('works with single letters', () => { + expect(caesar('A', 1)).toBe('B'); +}); +test.skip('works with words', () => { + expect(caesar('Aaa', 1)).toBe('Bbb'); +}); +test.skip('works with phrases', () => { + expect(caesar('Hello, World!', 5)).toBe('Mjqqt, Btwqi!'); +}); +test.skip('works with negative shift', () => { + expect(caesar('Mjqqt, Btwqi!', -5)).toBe('Hello, World!'); +}); +test.skip('wraps', () => { + expect(caesar('Z', 1)).toBe('A'); +}); +test.skip('works with large shift factors', () => { + expect(caesar('Hello, World!', 75)).toBe('Ebiil, Tloia!'); +}); +test.skip('works with large negative shift factors', () => { + expect(caesar('Hello, World!', -29)).toBe('Ebiil, Tloia!'); +}); From 4a112362c8ac620f9a8b8f0bcdae3dbb49a01991 Mon Sep 17 00:00:00 2001 From: thatblindgeye Date: Sat, 21 Jan 2023 12:53:41 -0500 Subject: [PATCH 2/7] Update files --- 01_helloWorld/solution/helloWorld-solution.js | 2 +- .../solution/helloWorld-solution.spec.js | 10 +- .../solution/repeatString-solution.js | 12 +- .../solution/repeatString-solution.spec.js | 64 +++++----- .../solution/reverseString-solution.js | 2 +- .../solution/reverseString-solution.spec.js | 28 ++-- .../solution/removeFromArray-solution.js | 35 +++-- .../solution/removeFromArray-solution.spec.js | 49 ++++--- 05_sumAll/solution/sumAll-solution.js | 24 ++-- 05_sumAll/solution/sumAll-solution.spec.js | 43 ++++--- 06_leapYears/solution/leapYears-solution.js | 2 +- .../solution/leapYears-solution.spec.js | 40 +++--- .../solution/tempConversion-solution.js | 12 +- .../solution/tempConversion-solution.spec.js | 42 +++--- 08_calculator/solution/calculator-solution.js | 46 +++---- .../solution/calculator-solution.spec.js | 110 ++++++++-------- .../solution/palindromes-solution.js | 4 +- .../solution/palindromes-solution.spec.js | 44 +++---- 10_fibonacci/solution/fibonacci-solution.js | 20 +-- .../solution/fibonacci-solution.spec.js | 58 ++++----- .../solution/getTheTitles-solution.js | 2 +- .../solution/getTheTitles-solution.spec.js | 30 ++--- .../solution/findTheOldest-solution.js | 24 ++-- .../solution/findTheOldest-solution.spec.js | 120 +++++++++--------- 13_caesar/solution/caesar-solution.js | 22 ++-- 13_caesar/solution/caesar-solution.spec.js | 30 ++--- README.md | 23 ++-- pigLatin/solution/pigLatin-solution.js | 21 +++ pigLatin/solution/pigLatin-solution.spec.js | 56 ++++++++ snakeCase/solution/snakeCase-solution.js | 19 +++ snakeCase/solution/snakeCase-solution.spec.js | 26 ++++ 31 files changed, 571 insertions(+), 449 deletions(-) create mode 100644 pigLatin/solution/pigLatin-solution.js create mode 100644 pigLatin/solution/pigLatin-solution.spec.js create mode 100644 snakeCase/solution/snakeCase-solution.js create mode 100644 snakeCase/solution/snakeCase-solution.spec.js diff --git a/01_helloWorld/solution/helloWorld-solution.js b/01_helloWorld/solution/helloWorld-solution.js index 002f305..46569e0 100644 --- a/01_helloWorld/solution/helloWorld-solution.js +++ b/01_helloWorld/solution/helloWorld-solution.js @@ -1,5 +1,5 @@ const helloWorld = function () { - return 'Hello, World!'; + return "Hello, World!"; }; module.exports = helloWorld; diff --git a/01_helloWorld/solution/helloWorld-solution.spec.js b/01_helloWorld/solution/helloWorld-solution.spec.js index 364645d..5070e7f 100644 --- a/01_helloWorld/solution/helloWorld-solution.spec.js +++ b/01_helloWorld/solution/helloWorld-solution.spec.js @@ -1,7 +1,7 @@ -const helloWorld = require('./helloWorld-solution'); +const helloWorld = require("./helloWorld"); -describe('Hello World', function () { - test('says "Hello, World!"', function () { - expect(helloWorld()).toEqual('Hello, World!'); - }); +describe("Hello World", function () { + test('says "Hello, World!"', function () { + expect(helloWorld()).toEqual("Hello, World!"); + }); }); diff --git a/02_repeatString/solution/repeatString-solution.js b/02_repeatString/solution/repeatString-solution.js index e8ea93e..67a765e 100644 --- a/02_repeatString/solution/repeatString-solution.js +++ b/02_repeatString/solution/repeatString-solution.js @@ -1,10 +1,10 @@ const repeatString = function (word, times) { - if (times < 0) return 'ERROR'; - let string = ''; - for (let i = 0; i < times; i++) { - string += word; - } - return string; + if (times < 0) return "ERROR"; + let string = ""; + for (let i = 0; i < times; i++) { + string += word; + } + return string; }; module.exports = repeatString; diff --git a/02_repeatString/solution/repeatString-solution.spec.js b/02_repeatString/solution/repeatString-solution.spec.js index 299874b..a4e2b0c 100644 --- a/02_repeatString/solution/repeatString-solution.spec.js +++ b/02_repeatString/solution/repeatString-solution.spec.js @@ -1,41 +1,39 @@ -const repeatString = require('./repeatString-solution'); +const repeatString = require("./repeatString"); -describe('repeatString', () => { - test('repeats the string', () => { - expect(repeatString('hey', 3)).toEqual('heyheyhey'); - }); - test.skip('repeats the string many times', () => { - expect(repeatString('hey', 10)).toEqual( - 'heyheyheyheyheyheyheyheyheyhey' - ); - }); - test.skip('repeats the string 1 times', () => { - expect(repeatString('hey', 1)).toEqual('hey'); - }); - test.skip('repeats the string 0 times', () => { - expect(repeatString('hey', 0)).toEqual(''); - }); - test.skip('returns ERROR with negative numbers', () => { - expect(repeatString('hey', -1)).toEqual('ERROR'); - }); - test.skip('repeats the string a random amount of times', function () { - /*The number is generated by using Math.random to get a value from between +describe("repeatString", () => { + test("repeats the string", () => { + expect(repeatString("hey", 3)).toEqual("heyheyhey"); + }); + test.skip("repeats the string many times", () => { + expect(repeatString("hey", 10)).toEqual("heyheyheyheyheyheyheyheyheyhey"); + }); + test.skip("repeats the string 1 times", () => { + expect(repeatString("hey", 1)).toEqual("hey"); + }); + test.skip("repeats the string 0 times", () => { + expect(repeatString("hey", 0)).toEqual(""); + }); + test.skip("returns ERROR with negative numbers", () => { + expect(repeatString("hey", -1)).toEqual("ERROR"); + }); + test.skip("repeats the string a random amount of times", function () { + /*The number is generated by using Math.random to get a value from between 0 to 1, when this is multiplied by 1000 and rounded down with Math.floor it equals a number between 0 to 999 (this number will change everytime you run the test).*/ - // DO NOT use Math.floor(Math.random() * 1000) in your code, - // this test generates a random number, then passes it into your code with a function parameter. - // If this doesn't make sense, you should go read about functions here: https://www.theodinproject.com/paths/foundations/courses/foundations/lessons/fundamentals-part-3 - const number = Math.floor(Math.random() * 1000); - /*The .match(/((hey))/g).length is a regex that will count the number of heys + // DO NOT use Math.floor(Math.random() * 1000) in your code, + // this test generates a random number, then passes it into your code with a function parameter. + // If this doesn't make sense, you should go read about functions here: https://www.theodinproject.com/paths/foundations/courses/foundations/lessons/fundamentals-part-3 + const number = Math.floor(Math.random() * 1000); + /*The .match(/((hey))/g).length is a regex that will count the number of heys in the result, which if your function works correctly will equal the number that was randomaly generated. */ - expect(repeatString('hey', number).match(/((hey))/g).length).toEqual( - number - ); - }); - test.skip('works with blank strings', () => { - expect(repeatString('', 10)).toEqual(''); - }); + expect(repeatString("hey", number).match(/((hey))/g).length).toEqual( + number + ); + }); + test.skip("works with blank strings", () => { + expect(repeatString("", 10)).toEqual(""); + }); }); diff --git a/03_reverseString/solution/reverseString-solution.js b/03_reverseString/solution/reverseString-solution.js index 7aee226..839f32e 100644 --- a/03_reverseString/solution/reverseString-solution.js +++ b/03_reverseString/solution/reverseString-solution.js @@ -1,5 +1,5 @@ const reverseString = function (string) { - return string.split('').reverse().join(''); + return string.split("").reverse().join(""); }; module.exports = reverseString; diff --git a/03_reverseString/solution/reverseString-solution.spec.js b/03_reverseString/solution/reverseString-solution.spec.js index 94b2624..ab0b079 100644 --- a/03_reverseString/solution/reverseString-solution.spec.js +++ b/03_reverseString/solution/reverseString-solution.spec.js @@ -1,18 +1,18 @@ -const reverseString = require('./reverseString-solution'); +const reverseString = require("./reverseString"); -describe('reverseString', () => { - test('reverses single word', () => { - expect(reverseString('hello')).toEqual('olleh'); - }); +describe("reverseString", () => { + test("reverses single word", () => { + expect(reverseString("hello")).toEqual("olleh"); + }); - test.skip('reverses multiple words', () => { - expect(reverseString('hello there')).toEqual('ereht olleh'); - }); + test.skip("reverses multiple words", () => { + expect(reverseString("hello there")).toEqual("ereht olleh"); + }); - test.skip('works with numbers and punctuation', () => { - expect(reverseString('123! abc!')).toEqual('!cba !321'); - }); - test.skip('works with blank strings', () => { - expect(reverseString('')).toEqual(''); - }); + test.skip("works with numbers and punctuation", () => { + expect(reverseString("123! abc!")).toEqual("!cba !321"); + }); + test.skip("works with blank strings", () => { + expect(reverseString("")).toEqual(""); + }); }); diff --git a/04_removeFromArray/solution/removeFromArray-solution.js b/04_removeFromArray/solution/removeFromArray-solution.js index 7399ed8..cc2b13a 100644 --- a/04_removeFromArray/solution/removeFromArray-solution.js +++ b/04_removeFromArray/solution/removeFromArray-solution.js @@ -1,29 +1,26 @@ // we have 2 solutions here, an easier one and a more advanced one. -// The easiest way to get an array of all of the arguments that are passed to a function +// The easiest way to get an array of the rest of the arguments that are passed to a function // is using the rest operator. If this is unfamiliar to you look it up! -const removeFromArray = function (...args) { - // the very first item in our list of arguments is the array, we pull it out with args[0] - const array = args[0]; - // create a new empty array - const newArray = []; - // use forEach to go through the array - array.forEach((item) => { - // push every element into the new array - // UNLESS it is included in the function arguments - // so we create a new array with every item, except those that should be removed - if (!args.includes(item)) { - newArray.push(item); - } - }); - // and return that array - return newArray; +const removeFromArray = function (array, ...args) { + // create a new empty array + const newArray = []; + // use forEach to go through the array + array.forEach((item) => { + // push every element into the new array + // UNLESS it is included in the function arguments + // so we create a new array with every item, except those that should be removed + if (!args.includes(item)) { + newArray.push(item); + } + }); + // and return that array + return newArray; }; // A simpler, but more advanced way to do it is to use the 'filter' function, // which basically does what we did with the forEach above. -// var removeFromArray = function(...args) { -// const array = args[0] +// var removeFromArray = function(array, ...args) { // return array.filter(val => !args.includes(val)) // } // diff --git a/04_removeFromArray/solution/removeFromArray-solution.spec.js b/04_removeFromArray/solution/removeFromArray-solution.spec.js index bc1eb1a..8c8a038 100644 --- a/04_removeFromArray/solution/removeFromArray-solution.spec.js +++ b/04_removeFromArray/solution/removeFromArray-solution.spec.js @@ -1,28 +1,25 @@ -const removeFromArray = require('./removeFromArray-solution'); +const removeFromArray = require("./removeFromArray"); -describe('removeFromArray', () => { - test('removes a single value', () => { - expect(removeFromArray([1, 2, 3, 4], 3)).toEqual([1, 2, 4]); - }); - test.skip('removes multiple values', () => { - expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]); - }); - test.skip('ignores non present values', () => { - expect(removeFromArray([1, 2, 3, 4], 7, 'tacos')).toEqual([1, 2, 3, 4]); - }); - test.skip('ignores non present values, but still works', () => { - expect(removeFromArray([1, 2, 3, 4], 7, 2)).toEqual([1, 3, 4]); - }); - test.skip('can remove all values', () => { - expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toEqual([]); - }); - test.skip('works with strings', () => { - expect(removeFromArray(['hey', 2, 3, 'ho'], 'hey', 3)).toEqual([ - 2, - 'ho', - ]); - }); - test.skip('only removes same type', () => { - expect(removeFromArray([1, 2, 3], '1', 3)).toEqual([1, 2]); - }); +describe("removeFromArray", () => { + test("removes a single value", () => { + expect(removeFromArray([1, 2, 3, 4], 3)).toEqual([1, 2, 4]); + }); + test.skip("removes multiple values", () => { + expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]); + }); + test.skip("ignores non present values", () => { + expect(removeFromArray([1, 2, 3, 4], 7, "tacos")).toEqual([1, 2, 3, 4]); + }); + test.skip("ignores non present values, but still works", () => { + expect(removeFromArray([1, 2, 3, 4], 7, 2)).toEqual([1, 3, 4]); + }); + test.skip("can remove all values", () => { + expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toEqual([]); + }); + test.skip("works with strings", () => { + expect(removeFromArray(["hey", 2, 3, "ho"], "hey", 3)).toEqual([2, "ho"]); + }); + test.skip("only removes same type", () => { + expect(removeFromArray([1, 2, 3], "1", 3)).toEqual([1, 2]); + }); }); diff --git a/05_sumAll/solution/sumAll-solution.js b/05_sumAll/solution/sumAll-solution.js index 9d95b64..50c78fe 100644 --- a/05_sumAll/solution/sumAll-solution.js +++ b/05_sumAll/solution/sumAll-solution.js @@ -1,16 +1,16 @@ const sumAll = function (min, max) { - if (!Number.isInteger(min) || !Number.isInteger(max)) return 'ERROR'; - if (min < 0 || max < 0) return 'ERROR'; - if (min > max) { - const temp = min; - min = max; - max = temp; - } - let sum = 0; - for (let i = min; i < max + 1; i++) { - sum += i; - } - return sum; + if (!Number.isInteger(min) || !Number.isInteger(max)) return "ERROR"; + if (min < 0 || max < 0) return "ERROR"; + if (min > max) { + const temp = min; + min = max; + max = temp; + } + let sum = 0; + for (let i = min; i < max + 1; i++) { + sum += i; + } + return sum; }; module.exports = sumAll; diff --git a/05_sumAll/solution/sumAll-solution.spec.js b/05_sumAll/solution/sumAll-solution.spec.js index ba30f62..bd4225f 100644 --- a/05_sumAll/solution/sumAll-solution.spec.js +++ b/05_sumAll/solution/sumAll-solution.spec.js @@ -1,22 +1,25 @@ -const sumAll = require('./sumAll-solution'); +const sumAll = require("./sumAll"); -describe('sumAll', () => { - test('sums numbers within the range', () => { - expect(sumAll(1, 4)).toEqual(10); - }); - test.skip('works with large numbers', () => { - expect(sumAll(1, 4000)).toEqual(8002000); - }); - test.skip('works with larger number first', () => { - expect(sumAll(123, 1)).toEqual(7626); - }); - test.skip('returns ERROR with negative numbers', () => { - expect(sumAll(-10, 4)).toEqual('ERROR'); - }); - test.skip('returns ERROR with non-number parameters', () => { - expect(sumAll(10, '90')).toEqual('ERROR'); - }); - test.skip('returns ERROR with non-number parameters', () => { - expect(sumAll(10, [90, 1])).toEqual('ERROR'); - }); +describe("sumAll", () => { + test("sums numbers within the range", () => { + expect(sumAll(1, 4)).toEqual(10); + }); + test.skip("works with large numbers", () => { + expect(sumAll(1, 4000)).toEqual(8002000); + }); + test.skip("works with larger number first", () => { + expect(sumAll(123, 1)).toEqual(7626); + }); + test.skip("returns ERROR with negative numbers", () => { + expect(sumAll(-10, 4)).toEqual("ERROR"); + }); + test.skip("returns ERROR with non-integer parameters", () => { + expect(sumAll(2.5, 4)).toEqual("ERROR"); + }); + test.skip("returns ERROR with non-number parameters", () => { + expect(sumAll(10, "90")).toEqual("ERROR"); + }); + test.skip("returns ERROR with non-number parameters", () => { + expect(sumAll(10, [90, 1])).toEqual("ERROR"); + }); }); diff --git a/06_leapYears/solution/leapYears-solution.js b/06_leapYears/solution/leapYears-solution.js index 31898b7..588bfd7 100644 --- a/06_leapYears/solution/leapYears-solution.js +++ b/06_leapYears/solution/leapYears-solution.js @@ -1,5 +1,5 @@ const leapYears = function (year) { - return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0); + return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0); }; module.exports = leapYears; diff --git a/06_leapYears/solution/leapYears-solution.spec.js b/06_leapYears/solution/leapYears-solution.spec.js index bcc422c..01658ac 100644 --- a/06_leapYears/solution/leapYears-solution.spec.js +++ b/06_leapYears/solution/leapYears-solution.spec.js @@ -1,22 +1,22 @@ -const leapYears = require('./leapYears-solution'); +const leapYears = require("./leapYears"); -describe('leapYears', () => { - test('works with non century years', () => { - expect(leapYears(1996)).toBe(true); - }); - test.skip('works with non century years', () => { - expect(leapYears(1997)).toBe(false); - }); - test.skip('works with ridiculously futuristic non century years', () => { - expect(leapYears(34992)).toBe(true); - }); - test.skip('works with century years', () => { - expect(leapYears(1900)).toBe(false); - }); - test.skip('works with century years', () => { - expect(leapYears(1600)).toBe(true); - }); - test.skip('works with century years', () => { - expect(leapYears(700)).toBe(false); - }); +describe("leapYears", () => { + test("works with non century years", () => { + expect(leapYears(1996)).toBe(true); + }); + test.skip("works with non century years", () => { + expect(leapYears(1997)).toBe(false); + }); + test.skip("works with ridiculously futuristic non century years", () => { + expect(leapYears(34992)).toBe(true); + }); + test.skip("works with century years", () => { + expect(leapYears(1900)).toBe(false); + }); + test.skip("works with century years", () => { + expect(leapYears(1600)).toBe(true); + }); + test.skip("works with century years", () => { + expect(leapYears(700)).toBe(false); + }); }); diff --git a/07_tempConversion/solution/tempConversion-solution.js b/07_tempConversion/solution/tempConversion-solution.js index a5fad55..48883dc 100644 --- a/07_tempConversion/solution/tempConversion-solution.js +++ b/07_tempConversion/solution/tempConversion-solution.js @@ -1,12 +1,12 @@ -const ftoc = function (f) { - return Math.round((f - 32) * (5 / 9) * 10) / 10; +const convertToCelsius = function (fahrenheit) { + return Math.round((fahrenheit - 32) * (5 / 9) * 10) / 10; }; -const ctof = function (c) { - return Math.round(((c * 9) / 5 + 32) * 10) / 10; +const convertToFahrenheit = function (celsius) { + return Math.round(((celsius * 9) / 5 + 32) * 10) / 10; }; module.exports = { - ftoc, - ctof, + convertToCelsius, + convertToFahrenheit, }; diff --git a/07_tempConversion/solution/tempConversion-solution.spec.js b/07_tempConversion/solution/tempConversion-solution.spec.js index 001351d..7a9e8c9 100644 --- a/07_tempConversion/solution/tempConversion-solution.spec.js +++ b/07_tempConversion/solution/tempConversion-solution.spec.js @@ -1,25 +1,25 @@ -const { ftoc, ctof } = require('./tempConversion-solution'); +const { convertToCelsius, convertToFahrenheit } = require("./tempConversion"); -describe('ftoc', () => { - test('works', () => { - expect(ftoc(32)).toEqual(0); - }); - test.skip('rounds to 1 decimal', () => { - expect(ftoc(100)).toEqual(37.8); - }); - test.skip('works with negatives', () => { - expect(ftoc(-100)).toEqual(-73.3); - }); +describe("convertToCelsius", () => { + test("works", () => { + expect(convertToCelsius(32)).toEqual(0); + }); + test.skip("rounds to 1 decimal", () => { + expect(convertToCelsius(100)).toEqual(37.8); + }); + test.skip("works with negatives", () => { + expect(convertToCelsius(-100)).toEqual(-73.3); + }); }); -describe('ctof', () => { - test.skip('works', () => { - expect(ctof(0)).toEqual(32); - }); - test.skip('rounds to 1 decimal', () => { - expect(ctof(73.2)).toEqual(163.8); - }); - test.skip('works with negatives', () => { - expect(ctof(-10)).toEqual(14); - }); +describe("convertToFahrenheit", () => { + test.skip("works", () => { + expect(convertToFahrenheit(0)).toEqual(32); + }); + test.skip("rounds to 1 decimal", () => { + expect(convertToFahrenheit(73.2)).toEqual(163.8); + }); + test.skip("works with negatives", () => { + expect(convertToFahrenheit(-10)).toEqual(14); + }); }); diff --git a/08_calculator/solution/calculator-solution.js b/08_calculator/solution/calculator-solution.js index ea9874a..0a247ec 100644 --- a/08_calculator/solution/calculator-solution.js +++ b/08_calculator/solution/calculator-solution.js @@ -1,48 +1,48 @@ const add = function (a, b) { - return a + b; + return a + b; }; const subtract = function (a, b) { - return a - b; + return a - b; }; const sum = function (array) { - return array.reduce((total, current) => total + current, 0); + return array.reduce((total, current) => total + current, 0); }; const multiply = function (array) { - return array.length - ? array.reduce((accumulator, nextItem) => accumulator * nextItem) - : 0; + return array.length + ? array.reduce((accumulator, nextItem) => accumulator * nextItem) + : 0; }; const power = function (a, b) { - return Math.pow(a, b); + return Math.pow(a, b); }; const factorial = function (n) { - if (n === 0) return 1; - let product = 1; - for (let i = n; i > 0; i--) { - product *= i; - } - return product; + if (n === 0) return 1; + let product = 1; + for (let i = n; i > 0; i--) { + product *= i; + } + return product; }; // This is another implementation of Factorial that uses recursion // THANKS to @ThirtyThreeB! const recursiveFactorial = function (n) { - if (n === 0) { - return 1; - } - return n * recursiveFactorial(n - 1); + if (n === 0) { + return 1; + } + return n * recursiveFactorial(n - 1); }; module.exports = { - add, - subtract, - sum, - multiply, - power, - factorial, + add, + subtract, + sum, + multiply, + power, + factorial, }; diff --git a/08_calculator/solution/calculator-solution.spec.js b/08_calculator/solution/calculator-solution.spec.js index 3356e00..b1f3935 100644 --- a/08_calculator/solution/calculator-solution.spec.js +++ b/08_calculator/solution/calculator-solution.spec.js @@ -1,77 +1,77 @@ -const calculator = require('./calculator-solution'); +const calculator = require("./calculator"); -describe('add', () => { - test('adds 0 and 0', () => { - expect(calculator.add(0, 0)).toBe(0); - }); +describe("add", () => { + test("adds 0 and 0", () => { + expect(calculator.add(0, 0)).toBe(0); + }); - test.skip('adds 2 and 2', () => { - expect(calculator.add(2, 2)).toBe(4); - }); + test.skip("adds 2 and 2", () => { + expect(calculator.add(2, 2)).toBe(4); + }); - test.skip('adds positive numbers', () => { - expect(calculator.add(2, 6)).toBe(8); - }); + test.skip("adds positive numbers", () => { + expect(calculator.add(2, 6)).toBe(8); + }); }); -describe('subtract', () => { - test.skip('subtracts numbers', () => { - expect(calculator.subtract(10, 4)).toBe(6); - }); +describe("subtract", () => { + test.skip("subtracts numbers", () => { + expect(calculator.subtract(10, 4)).toBe(6); + }); }); -describe('sum', () => { - test.skip('computes the sum of an empty array', () => { - expect(calculator.sum([])).toBe(0); - }); +describe("sum", () => { + test.skip("computes the sum of an empty array", () => { + expect(calculator.sum([])).toBe(0); + }); - test.skip('computes the sum of an array of one number', () => { - expect(calculator.sum([7])).toBe(7); - }); + test.skip("computes the sum of an array of one number", () => { + expect(calculator.sum([7])).toBe(7); + }); - test.skip('computes the sum of an array of two numbers', () => { - expect(calculator.sum([7, 11])).toBe(18); - }); + test.skip("computes the sum of an array of two numbers", () => { + expect(calculator.sum([7, 11])).toBe(18); + }); - test.skip('computes the sum of an array of many numbers', () => { - expect(calculator.sum([1, 3, 5, 7, 9])).toBe(25); - }); + test.skip("computes the sum of an array of many numbers", () => { + expect(calculator.sum([1, 3, 5, 7, 9])).toBe(25); + }); }); -describe('multiply', () => { - test.skip('multiplies two numbers', () => { - expect(calculator.multiply([2, 4])).toBe(8); - }); +describe("multiply", () => { + test.skip("multiplies two numbers", () => { + expect(calculator.multiply([2, 4])).toBe(8); + }); - test.skip('multiplies several numbers', () => { - expect(calculator.multiply([2, 4, 6, 8, 10, 12, 14])).toBe(645120); - }); + test.skip("multiplies several numbers", () => { + expect(calculator.multiply([2, 4, 6, 8, 10, 12, 14])).toBe(645120); + }); }); -describe('power', () => { - test.skip('raises one number to the power of another number', () => { - expect(calculator.power(4, 3)).toBe(64); // 4 to third power is 64 - }); +describe("power", () => { + test.skip("raises one number to the power of another number", () => { + expect(calculator.power(4, 3)).toBe(64); // 4 to third power is 64 + }); }); -describe('factorial', () => { - test.skip('computes the factorial of 0', () => { - expect(calculator.factorial(0)).toBe(1); // 0! = 1 - }); +describe("factorial", () => { + test.skip("computes the factorial of 0", () => { + expect(calculator.factorial(0)).toBe(1); // 0! = 1 + }); - test.skip('computes the factorial of 1', () => { - expect(calculator.factorial(1)).toBe(1); - }); + test.skip("computes the factorial of 1", () => { + expect(calculator.factorial(1)).toBe(1); + }); - test.skip('computes the factorial of 2', () => { - expect(calculator.factorial(2)).toBe(2); - }); + test.skip("computes the factorial of 2", () => { + expect(calculator.factorial(2)).toBe(2); + }); - test.skip('computes the factorial of 5', () => { - expect(calculator.factorial(5)).toBe(120); - }); + test.skip("computes the factorial of 5", () => { + expect(calculator.factorial(5)).toBe(120); + }); - test.skip('computes the factorial of 10', () => { - expect(calculator.factorial(10)).toBe(3628800); - }); + test.skip("computes the factorial of 10", () => { + expect(calculator.factorial(10)).toBe(3628800); + }); }); diff --git a/09_palindromes/solution/palindromes-solution.js b/09_palindromes/solution/palindromes-solution.js index ffd5dbf..bc5ef94 100644 --- a/09_palindromes/solution/palindromes-solution.js +++ b/09_palindromes/solution/palindromes-solution.js @@ -1,6 +1,6 @@ const palindromes = function (string) { - processedString = string.toLowerCase().replace(/[^a-z]/g, ''); - return processedString.split('').reverse().join('') == processedString; + const processedString = string.toLowerCase().replace(/[^a-z]/g, ""); + return processedString.split("").reverse().join("") == processedString; }; module.exports = palindromes; diff --git a/09_palindromes/solution/palindromes-solution.spec.js b/09_palindromes/solution/palindromes-solution.spec.js index afcb47a..f94c207 100644 --- a/09_palindromes/solution/palindromes-solution.spec.js +++ b/09_palindromes/solution/palindromes-solution.spec.js @@ -1,24 +1,24 @@ -const palindromes = require('./palindromes-solution'); +const palindromes = require("./palindromes"); -describe('palindromes', () => { - test('works with single words', () => { - expect(palindromes('racecar')).toBe(true); - }); - test.skip('works with punctuation ', () => { - expect(palindromes('racecar!')).toBe(true); - }); - test.skip('works with upper-case letters ', () => { - expect(palindromes('Racecar!')).toBe(true); - }); - test.skip('works with multiple words', () => { - expect(palindromes('A car, a man, a maraca.')).toBe(true); - }); - test.skip('works with multiple words', () => { - expect( - palindromes('Animal loots foliated detail of stool lamina.') - ).toBe(true); - }); - test.skip("doesn't just always return true", () => { - expect(palindromes('ZZZZ car, a man, a maraca.')).toBe(false); - }); +describe("palindromes", () => { + test("works with single words", () => { + expect(palindromes("racecar")).toBe(true); + }); + test.skip("works with punctuation ", () => { + expect(palindromes("racecar!")).toBe(true); + }); + test.skip("works with upper-case letters ", () => { + expect(palindromes("Racecar!")).toBe(true); + }); + test.skip("works with multiple words", () => { + expect(palindromes("A car, a man, a maraca.")).toBe(true); + }); + test.skip("works with multiple words", () => { + expect(palindromes("Animal loots foliated detail of stool lamina.")).toBe( + true + ); + }); + test.skip("doesn't just always return true", () => { + expect(palindromes("ZZZZ car, a man, a maraca.")).toBe(false); + }); }); diff --git a/10_fibonacci/solution/fibonacci-solution.js b/10_fibonacci/solution/fibonacci-solution.js index 9f9a523..77add79 100644 --- a/10_fibonacci/solution/fibonacci-solution.js +++ b/10_fibonacci/solution/fibonacci-solution.js @@ -1,14 +1,14 @@ const fibonacci = function (count) { - if (count < 0) return 'OOPS'; - if (count === 0) return 0; - let a = 0; - let b = 1; - for (let i = 1; i < count; i++) { - const temp = b; - b = a + b; - a = temp; - } - return b; + if (count < 0) return "OOPS"; + if (count === 0) return 0; + let a = 0; + let b = 1; + for (let i = 1; i < count; i++) { + const temp = b; + b = a + b; + a = temp; + } + return b; }; module.exports = fibonacci; diff --git a/10_fibonacci/solution/fibonacci-solution.spec.js b/10_fibonacci/solution/fibonacci-solution.spec.js index 997f30d..bd1ab92 100644 --- a/10_fibonacci/solution/fibonacci-solution.spec.js +++ b/10_fibonacci/solution/fibonacci-solution.spec.js @@ -1,31 +1,31 @@ -const fibonacci = require('./fibonacci-solution'); +const fibonacci = require("./fibonacci"); -describe('fibonacci', () => { - test('4th fibonacci number is 3', () => { - expect(fibonacci(4)).toBe(3); - }); - test.skip('6th fibonacci number is 8', () => { - expect(fibonacci(6)).toBe(8); - }); - test.skip('10th fibonacci number is 55', () => { - expect(fibonacci(10)).toBe(55); - }); - test.skip('15th fibonacci number is 610', () => { - expect(fibonacci(15)).toBe(610); - }); - test.skip('25th fibonacci number is 75025', () => { - expect(fibonacci(25)).toBe(75025); - }); - test.skip("doesn't accept negatives", () => { - expect(fibonacci(-25)).toBe('OOPS'); - }); - test.skip('DOES accept strings', () => { - expect(fibonacci('1')).toBe(1); - }); - test.skip('DOES accept strings', () => { - expect(fibonacci('2')).toBe(1); - }); - test.skip('DOES accept strings', () => { - expect(fibonacci('8')).toBe(21); - }); +describe("fibonacci", () => { + test("4th fibonacci number is 3", () => { + expect(fibonacci(4)).toBe(3); + }); + test.skip("6th fibonacci number is 8", () => { + expect(fibonacci(6)).toBe(8); + }); + test.skip("10th fibonacci number is 55", () => { + expect(fibonacci(10)).toBe(55); + }); + test.skip("15th fibonacci number is 610", () => { + expect(fibonacci(15)).toBe(610); + }); + test.skip("25th fibonacci number is 75025", () => { + expect(fibonacci(25)).toBe(75025); + }); + test.skip("doesn't accept negatives", () => { + expect(fibonacci(-25)).toBe("OOPS"); + }); + test.skip("DOES accept strings", () => { + expect(fibonacci("1")).toBe(1); + }); + test.skip("DOES accept strings", () => { + expect(fibonacci("2")).toBe(1); + }); + test.skip("DOES accept strings", () => { + expect(fibonacci("8")).toBe(21); + }); }); diff --git a/11_getTheTitles/solution/getTheTitles-solution.js b/11_getTheTitles/solution/getTheTitles-solution.js index ebcf404..3146e88 100644 --- a/11_getTheTitles/solution/getTheTitles-solution.js +++ b/11_getTheTitles/solution/getTheTitles-solution.js @@ -1,5 +1,5 @@ const getTheTitles = function (array) { - return array.map((book) => book.title); + return array.map((book) => book.title); }; module.exports = getTheTitles; diff --git a/11_getTheTitles/solution/getTheTitles-solution.spec.js b/11_getTheTitles/solution/getTheTitles-solution.spec.js index e2dc20d..e6a00f7 100644 --- a/11_getTheTitles/solution/getTheTitles-solution.spec.js +++ b/11_getTheTitles/solution/getTheTitles-solution.spec.js @@ -1,18 +1,18 @@ -const getTheTitles = require('./getTheTitles-solution'); +const getTheTitles = require("./getTheTitles"); -describe('getTheTitles', () => { - const books = [ - { - title: 'Book', - author: 'Name', - }, - { - title: 'Book2', - author: 'Name2', - }, - ]; +describe("getTheTitles", () => { + const books = [ + { + title: "Book", + author: "Name", + }, + { + title: "Book2", + author: "Name2", + }, + ]; - test('gets titles', () => { - expect(getTheTitles(books)).toEqual(['Book', 'Book2']); - }); + test("gets titles", () => { + expect(getTheTitles(books)).toEqual(["Book", "Book2"]); + }); }); diff --git a/12_findTheOldest/solution/findTheOldest-solution.js b/12_findTheOldest/solution/findTheOldest-solution.js index d25a7ff..ae4e272 100644 --- a/12_findTheOldest/solution/findTheOldest-solution.js +++ b/12_findTheOldest/solution/findTheOldest-solution.js @@ -1,19 +1,19 @@ const findTheOldest = function (array) { - return array.reduce((oldest, currentPerson) => { - const oldestAge = getAge(oldest.yearOfBirth, oldest.yearOfDeath); - const currentAge = getAge( - currentPerson.yearOfBirth, - currentPerson.yearOfDeath - ); - return oldestAge < currentAge ? currentPerson : oldest; - }); + return array.reduce((oldest, currentPerson) => { + const oldestAge = getAge(oldest.yearOfBirth, oldest.yearOfDeath); + const currentAge = getAge( + currentPerson.yearOfBirth, + currentPerson.yearOfDeath + ); + return oldestAge < currentAge ? currentPerson : oldest; + }); }; const getAge = function (birth, death) { - if (!death) { - death = new Date().getFullYear(); - } - return death - birth; + if (!death) { + death = new Date().getFullYear(); + } + return death - birth; }; module.exports = findTheOldest; diff --git a/12_findTheOldest/solution/findTheOldest-solution.spec.js b/12_findTheOldest/solution/findTheOldest-solution.spec.js index 2a33aff..9f16fdf 100644 --- a/12_findTheOldest/solution/findTheOldest-solution.spec.js +++ b/12_findTheOldest/solution/findTheOldest-solution.spec.js @@ -1,62 +1,62 @@ -const findTheOldest = require('./findTheOldest-solution'); +const findTheOldest = require("./findTheOldest"); -describe('findTheOldest', () => { - test('finds the oldest person!', () => { - const people = [ - { - name: 'Carly', - yearOfBirth: 1942, - yearOfDeath: 1970, - }, - { - name: 'Ray', - yearOfBirth: 1962, - yearOfDeath: 2011, - }, - { - name: 'Jane', - yearOfBirth: 1912, - yearOfDeath: 1941, - }, - ]; - expect(findTheOldest(people).name).toBe('Ray'); - }); - test.skip('finds the oldest person if someone is still living', () => { - const people = [ - { - name: 'Carly', - yearOfBirth: 2018, - }, - { - name: 'Ray', - yearOfBirth: 1962, - yearOfDeath: 2011, - }, - { - name: 'Jane', - yearOfBirth: 1912, - yearOfDeath: 1941, - }, - ]; - expect(findTheOldest(people).name).toBe('Ray'); - }); - test.skip('finds the oldest person if the OLDEST is still living', () => { - const people = [ - { - name: 'Carly', - yearOfBirth: 1066, - }, - { - name: 'Ray', - yearOfBirth: 1962, - yearOfDeath: 2011, - }, - { - name: 'Jane', - yearOfBirth: 1912, - yearOfDeath: 1941, - }, - ]; - expect(findTheOldest(people).name).toBe('Carly'); - }); +describe("findTheOldest", () => { + test("finds the oldest person!", () => { + const people = [ + { + name: "Carly", + yearOfBirth: 1942, + yearOfDeath: 1970, + }, + { + name: "Ray", + yearOfBirth: 1962, + yearOfDeath: 2011, + }, + { + name: "Jane", + yearOfBirth: 1912, + yearOfDeath: 1941, + }, + ]; + expect(findTheOldest(people).name).toBe("Ray"); + }); + test.skip("finds the oldest person if someone is still living", () => { + const people = [ + { + name: "Carly", + yearOfBirth: 2018, + }, + { + name: "Ray", + yearOfBirth: 1962, + yearOfDeath: 2011, + }, + { + name: "Jane", + yearOfBirth: 1912, + yearOfDeath: 1941, + }, + ]; + expect(findTheOldest(people).name).toBe("Ray"); + }); + test.skip("finds the oldest person if the OLDEST is still living", () => { + const people = [ + { + name: "Carly", + yearOfBirth: 1066, + }, + { + name: "Ray", + yearOfBirth: 1962, + yearOfDeath: 2011, + }, + { + name: "Jane", + yearOfBirth: 1912, + yearOfDeath: 1941, + }, + ]; + expect(findTheOldest(people).name).toBe("Carly"); + }); }); diff --git a/13_caesar/solution/caesar-solution.js b/13_caesar/solution/caesar-solution.js index fed2bdf..2f5c271 100644 --- a/13_caesar/solution/caesar-solution.js +++ b/13_caesar/solution/caesar-solution.js @@ -1,8 +1,8 @@ const caesar = function (string, shift) { - return string - .split('') - .map((char) => shiftChar(char, shift)) - .join(''); + return string + .split("") + .map((char) => shiftChar(char, shift)) + .join(""); }; const codeSet = (code) => (code < 97 ? 65 : 97); @@ -13,14 +13,14 @@ const codeSet = (code) => (code < 97 ? 65 : 97); const mod = (n, m) => ((n % m) + m) % m; const shiftChar = (char, shift) => { - const code = char.charCodeAt(); + const code = char.charCodeAt(); - if ((code >= 65 && code <= 90) || (code >= 97 && code <= 122)) { - return String.fromCharCode( - mod(code + shift - codeSet(code), 26) + codeSet(code) - ); - } - return char; + if ((code >= 65 && code <= 90) || (code >= 97 && code <= 122)) { + return String.fromCharCode( + mod(code + shift - codeSet(code), 26) + codeSet(code) + ); + } + return char; }; module.exports = caesar; diff --git a/13_caesar/solution/caesar-solution.spec.js b/13_caesar/solution/caesar-solution.spec.js index 68902ad..87fc253 100644 --- a/13_caesar/solution/caesar-solution.spec.js +++ b/13_caesar/solution/caesar-solution.spec.js @@ -1,23 +1,23 @@ -const caesar = require('./caesar-solution'); +const caesar = require("./caesar"); -test('works with single letters', () => { - expect(caesar('A', 1)).toBe('B'); +test("works with single letters", () => { + expect(caesar("A", 1)).toBe("B"); }); -test.skip('works with words', () => { - expect(caesar('Aaa', 1)).toBe('Bbb'); +test.skip("works with words", () => { + expect(caesar("Aaa", 1)).toBe("Bbb"); }); -test.skip('works with phrases', () => { - expect(caesar('Hello, World!', 5)).toBe('Mjqqt, Btwqi!'); +test.skip("works with phrases", () => { + expect(caesar("Hello, World!", 5)).toBe("Mjqqt, Btwqi!"); }); -test.skip('works with negative shift', () => { - expect(caesar('Mjqqt, Btwqi!', -5)).toBe('Hello, World!'); +test.skip("works with negative shift", () => { + expect(caesar("Mjqqt, Btwqi!", -5)).toBe("Hello, World!"); }); -test.skip('wraps', () => { - expect(caesar('Z', 1)).toBe('A'); +test.skip("wraps", () => { + expect(caesar("Z", 1)).toBe("A"); }); -test.skip('works with large shift factors', () => { - expect(caesar('Hello, World!', 75)).toBe('Ebiil, Tloia!'); +test.skip("works with large shift factors", () => { + expect(caesar("Hello, World!", 75)).toBe("Ebiil, Tloia!"); }); -test.skip('works with large negative shift factors', () => { - expect(caesar('Hello, World!', -29)).toBe('Ebiil, Tloia!'); +test.skip("works with large negative shift factors", () => { + expect(caesar("Hello, World!", -29)).toBe("Ebiil, Tloia!"); }); diff --git a/README.md b/README.md index c90ecc6..061f41c 100644 --- a/README.md +++ b/README.md @@ -10,17 +10,22 @@ If you have a suggestion to improve an exercise, an idea for a new exercise, or ## How To Use These Exercises -1. Fork and clone this repository. To learn how to fork a repository, see the GitHub documentation on how to [fork a repo](https://docs.github.com/en/get-started/quickstart/fork-a-repo). - * Copies of repositories on your machine are called clones. If you need help cloning to your local environment you can learn how from the GitHub documentation on [cloning a repository](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository-from-github/cloning-a-repository). +1. Fork and clone this repository. To learn how to fork a repository, see the GitHub documentation on how to [fork a repo](https://docs.github.com/en/get-started/quickstart/fork-a-repo). + - Copies of repositories on your machine are called clones. If you need help cloning to your local environment you can learn how from the GitHub documentation on [cloning a repository](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository-from-github/cloning-a-repository). 2. Before you start working on any execises, you should first ensure you have the following installed: - * **NPM**. You should have installed NPM already in our [Installing Node.js](https://www.theodinproject.com/paths/foundations/courses/foundations/lessons/installing-node-js) lesson. Just in case you need to check, type `npm --version` in your terminal. If you get back `Command 'npm' not found, but can be installed with:`, **do not follow the instructions in the terminal** to install with `apt-get` as this causes permission issues. Instead, go back to the installation lesson and install Node with NVM by following the instructions there. - * **Jest**. After cloning this repository to your local machine and installing NPM, go into the newly created directory (`cd javascript-exercises`) and run `npm install`. This will install Jest and set up the testing platform based on our preconfigured settings. -3. Each exercise includes 3 files: a markdown file with a description of the task, an empty (or mostly empty) JavaScript file, and a set of tests. To complete an exercise, you'll need to go to the exercise directory with `cd exerciseName` in the terminal and run `npm test exerciseName.spec.js`. This should run the test file and show you the output. - * When you first run a test, it will fail. This is by design! You must open the exercise file and write the code needed to get the test to pass. + - **NPM**. You should have installed NPM already in our [Installing Node.js](https://www.theodinproject.com/paths/foundations/courses/foundations/lessons/installing-node-js) lesson. Just in case you need to check, type `npm --version` in your terminal. If you get back `Command 'npm' not found, but can be installed with:`, **do not follow the instructions in the terminal** to install with `apt-get` as this causes permission issues. Instead, go back to the installation lesson and install Node with NVM by following the instructions there. + - **Jest**. After cloning this repository to your local machine and installing NPM, go into the newly created directory (`cd javascript-exercises`) and run `npm install`. This will install Jest and set up the testing platform based on our preconfigured settings. +3. Each exercise includes the following: + + - A markdown file with a description of the task, an empty (or mostly empty) JavaScript file, and a set of tests. + - A `solutions` directory that contains a solution and the same test file with all of the tests unskipped. + + To complete an exercise, you'll need to go to the exercise directory with `cd exerciseName` in the terminal and run `npm test exerciseName.spec.js`. This should run the test file and show you the output. When you first run a test, it will fail. This is by design! You must open the exercise file and write the code needed to get the test to pass. + 4. Some of the exercises have test conditions defined in their spec file as `test.skip` compared to `test`. This is purposeful. After you pass one `test`, you will change the next `test.skip` to `test` and test your code again. You'll do this until all conditions are satisfied. **All tests must pass at the same time**, and you should not have any `test.skip` instances by the time you finish an exercise. -5. Once you successfully finish an exercise, check TOP's `solutions` branch to compare it with yours. - * You should not be checking the solution for an exercise until you finish it! - * Keep in mind that TOP's solution is not the only solution. Generally as long as all of the tests pass, your solution should be fine. +5. Once you successfully finish an exercise, check the `solutions` directory within each exercise to compare it with yours. + - You should not be checking the solution for an exercise until you finish it! + - Keep in mind that TOP's solution is not the only solution. Generally as long as all of the tests pass, your solution should be fine. 6. Do not submit your solutions to this repo, as any PRs that do so will be closed without merging. **Note**: Due to the way Jest handles failed tests, it may return an exit code of 1 if any tests fail. NPM will interpret this as an error and you may see some `npm ERR!` messages after Jest runs. You can ignore these, or run your test with `npm test exerciseName.spec.js --silent` to supress the errors. diff --git a/pigLatin/solution/pigLatin-solution.js b/pigLatin/solution/pigLatin-solution.js new file mode 100644 index 0000000..259b61b --- /dev/null +++ b/pigLatin/solution/pigLatin-solution.js @@ -0,0 +1,21 @@ +const pigLatin = function (string) { + return string + .split(" ") + .map((word) => { + const index = firstVowelIndex(word); + const beginning = word.slice(0, index); + const ending = word.slice(index); + return `${ending}${beginning}ay`; + }) + .join(" "); +}; + +const firstVowelIndex = function (string) { + const vowels = string.match(/[aeiou]/g); + if (vowels[0] == "u" && string[string.indexOf(vowels[0]) - 1] == "q") { + return string.indexOf(vowels[1]); + } + return string.indexOf(vowels[0]); +}; + +module.exports = pigLatin; diff --git a/pigLatin/solution/pigLatin-solution.spec.js b/pigLatin/solution/pigLatin-solution.spec.js new file mode 100644 index 0000000..cb6e836 --- /dev/null +++ b/pigLatin/solution/pigLatin-solution.spec.js @@ -0,0 +1,56 @@ +const pigLatin = require("./pigLatin"); + +// Topics + +// * modules +// * strings + +// Pig Latin + +// Pig Latin is a made-up children's language that's intended to be confusing. test obeys a few simple rules (below) but when test's spoken quickly test's really difficult for non-children (and non-native speakers) to understand. + +// Rule 1: If a word begins with a vowel sound, add an "ay" sound to the end of the word. + +// Rule 2: If a word begins with a consonant sound, move test to the end of the word, and then add an "ay" sound to the end of the word. + +// (There are a few more rules for edge cases, and there are regional variants too, but that should be enough to understand the tests.) + +// See https://en.wikipedia.org/wiki/Pig_Latin for more details. + +describe("translate", () => { + test("translates a word beginning with a vowel", () => { + expect(pigLatin("apple")).toBe("appleay"); + }); + + test.skip("translates a word beginning with a consonant", () => { + expect(pigLatin("banana")).toBe("ananabay"); + }); + + test.skip("translates a word beginning with two consonants", () => { + expect(pigLatin("cherry")).toBe("errychay"); + }); + + test.skip("translates two words", () => { + expect(pigLatin("eat pie")).toBe("eatay iepay"); + }); + + test.skip("translates a word beginning with three consonants", () => { + expect(pigLatin("three")).toBe("eethray"); + }); + + test.skip('counts "sch" as a single phoneme', () => { + expect(pigLatin("school")).toBe("oolschay"); + }); + + test.skip('counts "qu" as a single phoneme', () => { + expect(pigLatin("quiet")).toBe("ietquay"); + }); + + test.skip('counts "qu" as a consonant even when its preceded by a consonant', () => { + expect(pigLatin("square")).toBe("aresquay"); + }); + + test.skip("translates many words", () => { + expect(pigLatin("the quick brown fox")).toBe("ethay ickquay ownbray oxfay"); + }); +}); diff --git a/snakeCase/solution/snakeCase-solution.js b/snakeCase/solution/snakeCase-solution.js new file mode 100644 index 0000000..bfc3126 --- /dev/null +++ b/snakeCase/solution/snakeCase-solution.js @@ -0,0 +1,19 @@ +const snakeCase = function (string) { + // wtf case + string = string.replace(/\.\./g, " "); + + // this splits up camelcase IF there are no spaces in the word + if (string.indexOf(" ") < 0) { + string = string.replace(/([A-Z])/g, " $1"); + } + + return string + .trim() + .toLowerCase() + .replace(/[,\?\.]/g, "") + .replace(/\-/g, " ") + .split(" ") + .join("_"); +}; + +module.exports = snakeCase; diff --git a/snakeCase/solution/snakeCase-solution.spec.js b/snakeCase/solution/snakeCase-solution.spec.js new file mode 100644 index 0000000..b8620a2 --- /dev/null +++ b/snakeCase/solution/snakeCase-solution.spec.js @@ -0,0 +1,26 @@ +const snakeCase = require("./snakeCase"); + +describe("snakeCase", () => { + test("works with simple lowercased phrases", () => { + expect(snakeCase("hello world")).toEqual("hello_world"); + }); + test.skip("works with Caps and punctuation", () => { + expect(snakeCase("Hello, World???")).toEqual("hello_world"); + }); + test.skip("works with longer phrases", () => { + expect(snakeCase("This is the song that never ends....")).toEqual( + "this_is_the_song_that_never_ends" + ); + }); + test.skip("works with camel case", () => { + expect(snakeCase("snakeCase")).toEqual("snake_case"); + }); + test.skip("works with kebab case", () => { + expect(snakeCase("snake-case")).toEqual("snake_case"); + }); + test.skip("works with WTF case", () => { + expect(snakeCase("SnAkE..CaSe..Is..AwEsOmE")).toEqual( + "snake_case_is_awesome" + ); + }); +}); From 2ec0f4344d94b047aaeb80037136d33f39515426 Mon Sep 17 00:00:00 2001 From: thatblindgeye Date: Wed, 1 Feb 2023 18:53:54 -0500 Subject: [PATCH 3/7] Updated file paths --- .../solution/helloWorld-solution.spec.js | 6 +-- .../solution/repeatString-solution.spec.js | 32 ++++++------- .../solution/reverseString-solution.spec.js | 20 ++++---- .../solution/removeFromArray-solution.spec.js | 24 +++++----- 05_sumAll/solution/sumAll-solution.spec.js | 26 +++++------ .../solution/leapYears-solution.spec.js | 16 +++---- .../solution/tempConversion-solution.spec.js | 21 +++++---- .../solution/calculator-solution.spec.js | 46 +++++++++---------- .../solution/palindromes-solution.spec.js | 26 +++++------ .../solution/fibonacci-solution.spec.js | 28 +++++------ .../solution/getTheTitles-solution.spec.js | 16 +++---- .../solution/findTheOldest-solution.spec.js | 34 +++++++------- 13_caesar/solution/caesar-solution.spec.js | 30 ++++++------ {pigLatin => archived_pigLatin}/README.md | 0 {pigLatin => archived_pigLatin}/pigLatin.js | 0 .../pigLatin.spec.js | 0 .../solution/pigLatin-solution.js | 0 .../solution/pigLatin-solution.spec.js | 34 +++++++------- {snakeCase => archived_snakeCase}/README.md | 0 .../snakeCase.js | 0 .../snakeCase.spec.js | 0 .../solution/snakeCase-solution.js | 0 .../solution/snakeCase-solution.spec.js | 26 +++++++++++ snakeCase/solution/snakeCase-solution.spec.js | 26 ----------- 24 files changed, 207 insertions(+), 204 deletions(-) rename {pigLatin => archived_pigLatin}/README.md (100%) rename {pigLatin => archived_pigLatin}/pigLatin.js (100%) rename {pigLatin => archived_pigLatin}/pigLatin.spec.js (100%) rename {pigLatin => archived_pigLatin}/solution/pigLatin-solution.js (100%) rename {pigLatin => archived_pigLatin}/solution/pigLatin-solution.spec.js (53%) rename {snakeCase => archived_snakeCase}/README.md (100%) rename {snakeCase => archived_snakeCase}/snakeCase.js (100%) rename {snakeCase => archived_snakeCase}/snakeCase.spec.js (100%) rename {snakeCase => archived_snakeCase}/solution/snakeCase-solution.js (100%) create mode 100644 archived_snakeCase/solution/snakeCase-solution.spec.js delete mode 100644 snakeCase/solution/snakeCase-solution.spec.js diff --git a/01_helloWorld/solution/helloWorld-solution.spec.js b/01_helloWorld/solution/helloWorld-solution.spec.js index 5070e7f..210a7f8 100644 --- a/01_helloWorld/solution/helloWorld-solution.spec.js +++ b/01_helloWorld/solution/helloWorld-solution.spec.js @@ -1,7 +1,7 @@ -const helloWorld = require("./helloWorld"); +const helloWorld = require('./helloWorld-solution'); -describe("Hello World", function () { +describe('Hello World', function () { test('says "Hello, World!"', function () { - expect(helloWorld()).toEqual("Hello, World!"); + expect(helloWorld()).toEqual('Hello, World!'); }); }); diff --git a/02_repeatString/solution/repeatString-solution.spec.js b/02_repeatString/solution/repeatString-solution.spec.js index a4e2b0c..417e14f 100644 --- a/02_repeatString/solution/repeatString-solution.spec.js +++ b/02_repeatString/solution/repeatString-solution.spec.js @@ -1,22 +1,22 @@ -const repeatString = require("./repeatString"); +const repeatString = require('./repeatString-solution'); -describe("repeatString", () => { - test("repeats the string", () => { - expect(repeatString("hey", 3)).toEqual("heyheyhey"); +describe('repeatString', () => { + test('repeats the string', () => { + expect(repeatString('hey', 3)).toEqual('heyheyhey'); }); - test.skip("repeats the string many times", () => { - expect(repeatString("hey", 10)).toEqual("heyheyheyheyheyheyheyheyheyhey"); + test.skip('repeats the string many times', () => { + expect(repeatString('hey', 10)).toEqual('heyheyheyheyheyheyheyheyheyhey'); }); - test.skip("repeats the string 1 times", () => { - expect(repeatString("hey", 1)).toEqual("hey"); + test.skip('repeats the string 1 times', () => { + expect(repeatString('hey', 1)).toEqual('hey'); }); - test.skip("repeats the string 0 times", () => { - expect(repeatString("hey", 0)).toEqual(""); + test.skip('repeats the string 0 times', () => { + expect(repeatString('hey', 0)).toEqual(''); }); - test.skip("returns ERROR with negative numbers", () => { - expect(repeatString("hey", -1)).toEqual("ERROR"); + test.skip('returns ERROR with negative numbers', () => { + expect(repeatString('hey', -1)).toEqual('ERROR'); }); - test.skip("repeats the string a random amount of times", function () { + test.skip('repeats the string a random amount of times', function () { /*The number is generated by using Math.random to get a value from between 0 to 1, when this is multiplied by 1000 and rounded down with Math.floor it equals a number between 0 to 999 (this number will change everytime you run @@ -29,11 +29,11 @@ describe("repeatString", () => { /*The .match(/((hey))/g).length is a regex that will count the number of heys in the result, which if your function works correctly will equal the number that was randomaly generated. */ - expect(repeatString("hey", number).match(/((hey))/g).length).toEqual( + expect(repeatString('hey', number).match(/((hey))/g).length).toEqual( number ); }); - test.skip("works with blank strings", () => { - expect(repeatString("", 10)).toEqual(""); + test.skip('works with blank strings', () => { + expect(repeatString('', 10)).toEqual(''); }); }); diff --git a/03_reverseString/solution/reverseString-solution.spec.js b/03_reverseString/solution/reverseString-solution.spec.js index ab0b079..5ed33a1 100644 --- a/03_reverseString/solution/reverseString-solution.spec.js +++ b/03_reverseString/solution/reverseString-solution.spec.js @@ -1,18 +1,18 @@ -const reverseString = require("./reverseString"); +const reverseString = require('./reverseString-solution'); -describe("reverseString", () => { - test("reverses single word", () => { - expect(reverseString("hello")).toEqual("olleh"); +describe('reverseString', () => { + test('reverses single word', () => { + expect(reverseString('hello')).toEqual('olleh'); }); - test.skip("reverses multiple words", () => { - expect(reverseString("hello there")).toEqual("ereht olleh"); + test.skip('reverses multiple words', () => { + expect(reverseString('hello there')).toEqual('ereht olleh'); }); - test.skip("works with numbers and punctuation", () => { - expect(reverseString("123! abc!")).toEqual("!cba !321"); + test.skip('works with numbers and punctuation', () => { + expect(reverseString('123! abc!')).toEqual('!cba !321'); }); - test.skip("works with blank strings", () => { - expect(reverseString("")).toEqual(""); + test.skip('works with blank strings', () => { + expect(reverseString('')).toEqual(''); }); }); diff --git a/04_removeFromArray/solution/removeFromArray-solution.spec.js b/04_removeFromArray/solution/removeFromArray-solution.spec.js index 8c8a038..1916d98 100644 --- a/04_removeFromArray/solution/removeFromArray-solution.spec.js +++ b/04_removeFromArray/solution/removeFromArray-solution.spec.js @@ -1,25 +1,25 @@ -const removeFromArray = require("./removeFromArray"); +const removeFromArray = require('./removeFromArray-solution'); -describe("removeFromArray", () => { - test("removes a single value", () => { +describe('removeFromArray', () => { + test('removes a single value', () => { expect(removeFromArray([1, 2, 3, 4], 3)).toEqual([1, 2, 4]); }); - test.skip("removes multiple values", () => { + test.skip('removes multiple values', () => { expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]); }); - test.skip("ignores non present values", () => { - expect(removeFromArray([1, 2, 3, 4], 7, "tacos")).toEqual([1, 2, 3, 4]); + test.skip('ignores non present values', () => { + expect(removeFromArray([1, 2, 3, 4], 7, 'tacos')).toEqual([1, 2, 3, 4]); }); - test.skip("ignores non present values, but still works", () => { + test.skip('ignores non present values, but still works', () => { expect(removeFromArray([1, 2, 3, 4], 7, 2)).toEqual([1, 3, 4]); }); - test.skip("can remove all values", () => { + test.skip('can remove all values', () => { expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toEqual([]); }); - test.skip("works with strings", () => { - expect(removeFromArray(["hey", 2, 3, "ho"], "hey", 3)).toEqual([2, "ho"]); + test.skip('works with strings', () => { + expect(removeFromArray(['hey', 2, 3, 'ho'], 'hey', 3)).toEqual([2, 'ho']); }); - test.skip("only removes same type", () => { - expect(removeFromArray([1, 2, 3], "1", 3)).toEqual([1, 2]); + test.skip('only removes same type', () => { + expect(removeFromArray([1, 2, 3], '1', 3)).toEqual([1, 2]); }); }); diff --git a/05_sumAll/solution/sumAll-solution.spec.js b/05_sumAll/solution/sumAll-solution.spec.js index bd4225f..8cd9826 100644 --- a/05_sumAll/solution/sumAll-solution.spec.js +++ b/05_sumAll/solution/sumAll-solution.spec.js @@ -1,25 +1,25 @@ -const sumAll = require("./sumAll"); +const sumAll = require('./sumAll-solution'); -describe("sumAll", () => { - test("sums numbers within the range", () => { +describe('sumAll', () => { + test('sums numbers within the range', () => { expect(sumAll(1, 4)).toEqual(10); }); - test.skip("works with large numbers", () => { + test.skip('works with large numbers', () => { expect(sumAll(1, 4000)).toEqual(8002000); }); - test.skip("works with larger number first", () => { + test.skip('works with larger number first', () => { expect(sumAll(123, 1)).toEqual(7626); }); - test.skip("returns ERROR with negative numbers", () => { - expect(sumAll(-10, 4)).toEqual("ERROR"); + test.skip('returns ERROR with negative numbers', () => { + expect(sumAll(-10, 4)).toEqual('ERROR'); }); - test.skip("returns ERROR with non-integer parameters", () => { - expect(sumAll(2.5, 4)).toEqual("ERROR"); + test.skip('returns ERROR with non-integer parameters', () => { + expect(sumAll(2.5, 4)).toEqual('ERROR'); }); - test.skip("returns ERROR with non-number parameters", () => { - expect(sumAll(10, "90")).toEqual("ERROR"); + test.skip('returns ERROR with non-number parameters', () => { + expect(sumAll(10, '90')).toEqual('ERROR'); }); - test.skip("returns ERROR with non-number parameters", () => { - expect(sumAll(10, [90, 1])).toEqual("ERROR"); + test.skip('returns ERROR with non-number parameters', () => { + expect(sumAll(10, [90, 1])).toEqual('ERROR'); }); }); diff --git a/06_leapYears/solution/leapYears-solution.spec.js b/06_leapYears/solution/leapYears-solution.spec.js index 01658ac..3afd656 100644 --- a/06_leapYears/solution/leapYears-solution.spec.js +++ b/06_leapYears/solution/leapYears-solution.spec.js @@ -1,22 +1,22 @@ -const leapYears = require("./leapYears"); +const leapYears = require('./leapYears-solution'); -describe("leapYears", () => { - test("works with non century years", () => { +describe('leapYears', () => { + test('works with non century years', () => { expect(leapYears(1996)).toBe(true); }); - test.skip("works with non century years", () => { + test.skip('works with non century years', () => { expect(leapYears(1997)).toBe(false); }); - test.skip("works with ridiculously futuristic non century years", () => { + test.skip('works with ridiculously futuristic non century years', () => { expect(leapYears(34992)).toBe(true); }); - test.skip("works with century years", () => { + test.skip('works with century years', () => { expect(leapYears(1900)).toBe(false); }); - test.skip("works with century years", () => { + test.skip('works with century years', () => { expect(leapYears(1600)).toBe(true); }); - test.skip("works with century years", () => { + test.skip('works with century years', () => { expect(leapYears(700)).toBe(false); }); }); diff --git a/07_tempConversion/solution/tempConversion-solution.spec.js b/07_tempConversion/solution/tempConversion-solution.spec.js index 7a9e8c9..27a840a 100644 --- a/07_tempConversion/solution/tempConversion-solution.spec.js +++ b/07_tempConversion/solution/tempConversion-solution.spec.js @@ -1,25 +1,28 @@ -const { convertToCelsius, convertToFahrenheit } = require("./tempConversion"); +const { + convertToCelsius, + convertToFahrenheit, +} = require('./tempConversion-solution'); -describe("convertToCelsius", () => { - test("works", () => { +describe('convertToCelsius', () => { + test('works', () => { expect(convertToCelsius(32)).toEqual(0); }); - test.skip("rounds to 1 decimal", () => { + test.skip('rounds to 1 decimal', () => { expect(convertToCelsius(100)).toEqual(37.8); }); - test.skip("works with negatives", () => { + test.skip('works with negatives', () => { expect(convertToCelsius(-100)).toEqual(-73.3); }); }); -describe("convertToFahrenheit", () => { - test.skip("works", () => { +describe('convertToFahrenheit', () => { + test.skip('works', () => { expect(convertToFahrenheit(0)).toEqual(32); }); - test.skip("rounds to 1 decimal", () => { + test.skip('rounds to 1 decimal', () => { expect(convertToFahrenheit(73.2)).toEqual(163.8); }); - test.skip("works with negatives", () => { + test.skip('works with negatives', () => { expect(convertToFahrenheit(-10)).toEqual(14); }); }); diff --git a/08_calculator/solution/calculator-solution.spec.js b/08_calculator/solution/calculator-solution.spec.js index b1f3935..0e1090c 100644 --- a/08_calculator/solution/calculator-solution.spec.js +++ b/08_calculator/solution/calculator-solution.spec.js @@ -1,77 +1,77 @@ -const calculator = require("./calculator"); +const calculator = require('./calculator-solution'); -describe("add", () => { - test("adds 0 and 0", () => { +describe('add', () => { + test('adds 0 and 0', () => { expect(calculator.add(0, 0)).toBe(0); }); - test.skip("adds 2 and 2", () => { + test.skip('adds 2 and 2', () => { expect(calculator.add(2, 2)).toBe(4); }); - test.skip("adds positive numbers", () => { + test.skip('adds positive numbers', () => { expect(calculator.add(2, 6)).toBe(8); }); }); -describe("subtract", () => { - test.skip("subtracts numbers", () => { +describe('subtract', () => { + test.skip('subtracts numbers', () => { expect(calculator.subtract(10, 4)).toBe(6); }); }); -describe("sum", () => { - test.skip("computes the sum of an empty array", () => { +describe('sum', () => { + test.skip('computes the sum of an empty array', () => { expect(calculator.sum([])).toBe(0); }); - test.skip("computes the sum of an array of one number", () => { + test.skip('computes the sum of an array of one number', () => { expect(calculator.sum([7])).toBe(7); }); - test.skip("computes the sum of an array of two numbers", () => { + test.skip('computes the sum of an array of two numbers', () => { expect(calculator.sum([7, 11])).toBe(18); }); - test.skip("computes the sum of an array of many numbers", () => { + test.skip('computes the sum of an array of many numbers', () => { expect(calculator.sum([1, 3, 5, 7, 9])).toBe(25); }); }); -describe("multiply", () => { - test.skip("multiplies two numbers", () => { +describe('multiply', () => { + test.skip('multiplies two numbers', () => { expect(calculator.multiply([2, 4])).toBe(8); }); - test.skip("multiplies several numbers", () => { + test.skip('multiplies several numbers', () => { expect(calculator.multiply([2, 4, 6, 8, 10, 12, 14])).toBe(645120); }); }); -describe("power", () => { - test.skip("raises one number to the power of another number", () => { +describe('power', () => { + test.skip('raises one number to the power of another number', () => { expect(calculator.power(4, 3)).toBe(64); // 4 to third power is 64 }); }); -describe("factorial", () => { - test.skip("computes the factorial of 0", () => { +describe('factorial', () => { + test.skip('computes the factorial of 0', () => { expect(calculator.factorial(0)).toBe(1); // 0! = 1 }); - test.skip("computes the factorial of 1", () => { + test.skip('computes the factorial of 1', () => { expect(calculator.factorial(1)).toBe(1); }); - test.skip("computes the factorial of 2", () => { + test.skip('computes the factorial of 2', () => { expect(calculator.factorial(2)).toBe(2); }); - test.skip("computes the factorial of 5", () => { + test.skip('computes the factorial of 5', () => { expect(calculator.factorial(5)).toBe(120); }); - test.skip("computes the factorial of 10", () => { + test.skip('computes the factorial of 10', () => { expect(calculator.factorial(10)).toBe(3628800); }); }); diff --git a/09_palindromes/solution/palindromes-solution.spec.js b/09_palindromes/solution/palindromes-solution.spec.js index f94c207..b1f5d41 100644 --- a/09_palindromes/solution/palindromes-solution.spec.js +++ b/09_palindromes/solution/palindromes-solution.spec.js @@ -1,24 +1,24 @@ -const palindromes = require("./palindromes"); +const palindromes = require('./palindromes-solution'); -describe("palindromes", () => { - test("works with single words", () => { - expect(palindromes("racecar")).toBe(true); +describe('palindromes', () => { + test('works with single words', () => { + expect(palindromes('racecar')).toBe(true); }); - test.skip("works with punctuation ", () => { - expect(palindromes("racecar!")).toBe(true); + test.skip('works with punctuation ', () => { + expect(palindromes('racecar!')).toBe(true); }); - test.skip("works with upper-case letters ", () => { - expect(palindromes("Racecar!")).toBe(true); + test.skip('works with upper-case letters ', () => { + expect(palindromes('Racecar!')).toBe(true); }); - test.skip("works with multiple words", () => { - expect(palindromes("A car, a man, a maraca.")).toBe(true); + test.skip('works with multiple words', () => { + expect(palindromes('A car, a man, a maraca.')).toBe(true); }); - test.skip("works with multiple words", () => { - expect(palindromes("Animal loots foliated detail of stool lamina.")).toBe( + test.skip('works with multiple words', () => { + expect(palindromes('Animal loots foliated detail of stool lamina.')).toBe( true ); }); test.skip("doesn't just always return true", () => { - expect(palindromes("ZZZZ car, a man, a maraca.")).toBe(false); + expect(palindromes('ZZZZ car, a man, a maraca.')).toBe(false); }); }); diff --git a/10_fibonacci/solution/fibonacci-solution.spec.js b/10_fibonacci/solution/fibonacci-solution.spec.js index bd1ab92..abc6ffd 100644 --- a/10_fibonacci/solution/fibonacci-solution.spec.js +++ b/10_fibonacci/solution/fibonacci-solution.spec.js @@ -1,31 +1,31 @@ -const fibonacci = require("./fibonacci"); +const fibonacci = require('./fibonacci-solution'); -describe("fibonacci", () => { - test("4th fibonacci number is 3", () => { +describe('fibonacci', () => { + test('4th fibonacci number is 3', () => { expect(fibonacci(4)).toBe(3); }); - test.skip("6th fibonacci number is 8", () => { + test.skip('6th fibonacci number is 8', () => { expect(fibonacci(6)).toBe(8); }); - test.skip("10th fibonacci number is 55", () => { + test.skip('10th fibonacci number is 55', () => { expect(fibonacci(10)).toBe(55); }); - test.skip("15th fibonacci number is 610", () => { + test.skip('15th fibonacci number is 610', () => { expect(fibonacci(15)).toBe(610); }); - test.skip("25th fibonacci number is 75025", () => { + test.skip('25th fibonacci number is 75025', () => { expect(fibonacci(25)).toBe(75025); }); test.skip("doesn't accept negatives", () => { - expect(fibonacci(-25)).toBe("OOPS"); + expect(fibonacci(-25)).toBe('OOPS'); }); - test.skip("DOES accept strings", () => { - expect(fibonacci("1")).toBe(1); + test.skip('DOES accept strings', () => { + expect(fibonacci('1')).toBe(1); }); - test.skip("DOES accept strings", () => { - expect(fibonacci("2")).toBe(1); + test.skip('DOES accept strings', () => { + expect(fibonacci('2')).toBe(1); }); - test.skip("DOES accept strings", () => { - expect(fibonacci("8")).toBe(21); + test.skip('DOES accept strings', () => { + expect(fibonacci('8')).toBe(21); }); }); diff --git a/11_getTheTitles/solution/getTheTitles-solution.spec.js b/11_getTheTitles/solution/getTheTitles-solution.spec.js index e6a00f7..37e01dd 100644 --- a/11_getTheTitles/solution/getTheTitles-solution.spec.js +++ b/11_getTheTitles/solution/getTheTitles-solution.spec.js @@ -1,18 +1,18 @@ -const getTheTitles = require("./getTheTitles"); +const getTheTitles = require('./getTheTitles-solution'); -describe("getTheTitles", () => { +describe('getTheTitles', () => { const books = [ { - title: "Book", - author: "Name", + title: 'Book', + author: 'Name', }, { - title: "Book2", - author: "Name2", + title: 'Book2', + author: 'Name2', }, ]; - test("gets titles", () => { - expect(getTheTitles(books)).toEqual(["Book", "Book2"]); + test('gets titles', () => { + expect(getTheTitles(books)).toEqual(['Book', 'Book2']); }); }); diff --git a/12_findTheOldest/solution/findTheOldest-solution.spec.js b/12_findTheOldest/solution/findTheOldest-solution.spec.js index 9f16fdf..9b47c12 100644 --- a/12_findTheOldest/solution/findTheOldest-solution.spec.js +++ b/12_findTheOldest/solution/findTheOldest-solution.spec.js @@ -1,62 +1,62 @@ -const findTheOldest = require("./findTheOldest"); +const findTheOldest = require('./findTheOldest-solution'); -describe("findTheOldest", () => { - test("finds the oldest person!", () => { +describe('findTheOldest', () => { + test('finds the oldest person!', () => { const people = [ { - name: "Carly", + name: 'Carly', yearOfBirth: 1942, yearOfDeath: 1970, }, { - name: "Ray", + name: 'Ray', yearOfBirth: 1962, yearOfDeath: 2011, }, { - name: "Jane", + name: 'Jane', yearOfBirth: 1912, yearOfDeath: 1941, }, ]; - expect(findTheOldest(people).name).toBe("Ray"); + expect(findTheOldest(people).name).toBe('Ray'); }); - test.skip("finds the oldest person if someone is still living", () => { + test.skip('finds the oldest person if someone is still living', () => { const people = [ { - name: "Carly", + name: 'Carly', yearOfBirth: 2018, }, { - name: "Ray", + name: 'Ray', yearOfBirth: 1962, yearOfDeath: 2011, }, { - name: "Jane", + name: 'Jane', yearOfBirth: 1912, yearOfDeath: 1941, }, ]; - expect(findTheOldest(people).name).toBe("Ray"); + expect(findTheOldest(people).name).toBe('Ray'); }); - test.skip("finds the oldest person if the OLDEST is still living", () => { + test.skip('finds the oldest person if the OLDEST is still living', () => { const people = [ { - name: "Carly", + name: 'Carly', yearOfBirth: 1066, }, { - name: "Ray", + name: 'Ray', yearOfBirth: 1962, yearOfDeath: 2011, }, { - name: "Jane", + name: 'Jane', yearOfBirth: 1912, yearOfDeath: 1941, }, ]; - expect(findTheOldest(people).name).toBe("Carly"); + expect(findTheOldest(people).name).toBe('Carly'); }); }); diff --git a/13_caesar/solution/caesar-solution.spec.js b/13_caesar/solution/caesar-solution.spec.js index 87fc253..55e3852 100644 --- a/13_caesar/solution/caesar-solution.spec.js +++ b/13_caesar/solution/caesar-solution.spec.js @@ -1,23 +1,23 @@ -const caesar = require("./caesar"); +const caesar = require('./caesar-solution'); -test("works with single letters", () => { - expect(caesar("A", 1)).toBe("B"); +test('works with single letters', () => { + expect(caesar('A', 1)).toBe('B'); }); -test.skip("works with words", () => { - expect(caesar("Aaa", 1)).toBe("Bbb"); +test.skip('works with words', () => { + expect(caesar('Aaa', 1)).toBe('Bbb'); }); -test.skip("works with phrases", () => { - expect(caesar("Hello, World!", 5)).toBe("Mjqqt, Btwqi!"); +test.skip('works with phrases', () => { + expect(caesar('Hello, World!', 5)).toBe('Mjqqt, Btwqi!'); }); -test.skip("works with negative shift", () => { - expect(caesar("Mjqqt, Btwqi!", -5)).toBe("Hello, World!"); +test.skip('works with negative shift', () => { + expect(caesar('Mjqqt, Btwqi!', -5)).toBe('Hello, World!'); }); -test.skip("wraps", () => { - expect(caesar("Z", 1)).toBe("A"); +test.skip('wraps', () => { + expect(caesar('Z', 1)).toBe('A'); }); -test.skip("works with large shift factors", () => { - expect(caesar("Hello, World!", 75)).toBe("Ebiil, Tloia!"); +test.skip('works with large shift factors', () => { + expect(caesar('Hello, World!', 75)).toBe('Ebiil, Tloia!'); }); -test.skip("works with large negative shift factors", () => { - expect(caesar("Hello, World!", -29)).toBe("Ebiil, Tloia!"); +test.skip('works with large negative shift factors', () => { + expect(caesar('Hello, World!', -29)).toBe('Ebiil, Tloia!'); }); diff --git a/pigLatin/README.md b/archived_pigLatin/README.md similarity index 100% rename from pigLatin/README.md rename to archived_pigLatin/README.md diff --git a/pigLatin/pigLatin.js b/archived_pigLatin/pigLatin.js similarity index 100% rename from pigLatin/pigLatin.js rename to archived_pigLatin/pigLatin.js diff --git a/pigLatin/pigLatin.spec.js b/archived_pigLatin/pigLatin.spec.js similarity index 100% rename from pigLatin/pigLatin.spec.js rename to archived_pigLatin/pigLatin.spec.js diff --git a/pigLatin/solution/pigLatin-solution.js b/archived_pigLatin/solution/pigLatin-solution.js similarity index 100% rename from pigLatin/solution/pigLatin-solution.js rename to archived_pigLatin/solution/pigLatin-solution.js diff --git a/pigLatin/solution/pigLatin-solution.spec.js b/archived_pigLatin/solution/pigLatin-solution.spec.js similarity index 53% rename from pigLatin/solution/pigLatin-solution.spec.js rename to archived_pigLatin/solution/pigLatin-solution.spec.js index cb6e836..dbcd5a1 100644 --- a/pigLatin/solution/pigLatin-solution.spec.js +++ b/archived_pigLatin/solution/pigLatin-solution.spec.js @@ -1,4 +1,4 @@ -const pigLatin = require("./pigLatin"); +const pigLatin = require('./pigLatin-solution'); // Topics @@ -17,40 +17,40 @@ const pigLatin = require("./pigLatin"); // See https://en.wikipedia.org/wiki/Pig_Latin for more details. -describe("translate", () => { - test("translates a word beginning with a vowel", () => { - expect(pigLatin("apple")).toBe("appleay"); +describe('translate', () => { + test('translates a word beginning with a vowel', () => { + expect(pigLatin('apple')).toBe('appleay'); }); - test.skip("translates a word beginning with a consonant", () => { - expect(pigLatin("banana")).toBe("ananabay"); + test.skip('translates a word beginning with a consonant', () => { + expect(pigLatin('banana')).toBe('ananabay'); }); - test.skip("translates a word beginning with two consonants", () => { - expect(pigLatin("cherry")).toBe("errychay"); + test.skip('translates a word beginning with two consonants', () => { + expect(pigLatin('cherry')).toBe('errychay'); }); - test.skip("translates two words", () => { - expect(pigLatin("eat pie")).toBe("eatay iepay"); + test.skip('translates two words', () => { + expect(pigLatin('eat pie')).toBe('eatay iepay'); }); - test.skip("translates a word beginning with three consonants", () => { - expect(pigLatin("three")).toBe("eethray"); + test.skip('translates a word beginning with three consonants', () => { + expect(pigLatin('three')).toBe('eethray'); }); test.skip('counts "sch" as a single phoneme', () => { - expect(pigLatin("school")).toBe("oolschay"); + expect(pigLatin('school')).toBe('oolschay'); }); test.skip('counts "qu" as a single phoneme', () => { - expect(pigLatin("quiet")).toBe("ietquay"); + expect(pigLatin('quiet')).toBe('ietquay'); }); test.skip('counts "qu" as a consonant even when its preceded by a consonant', () => { - expect(pigLatin("square")).toBe("aresquay"); + expect(pigLatin('square')).toBe('aresquay'); }); - test.skip("translates many words", () => { - expect(pigLatin("the quick brown fox")).toBe("ethay ickquay ownbray oxfay"); + test.skip('translates many words', () => { + expect(pigLatin('the quick brown fox')).toBe('ethay ickquay ownbray oxfay'); }); }); diff --git a/snakeCase/README.md b/archived_snakeCase/README.md similarity index 100% rename from snakeCase/README.md rename to archived_snakeCase/README.md diff --git a/snakeCase/snakeCase.js b/archived_snakeCase/snakeCase.js similarity index 100% rename from snakeCase/snakeCase.js rename to archived_snakeCase/snakeCase.js diff --git a/snakeCase/snakeCase.spec.js b/archived_snakeCase/snakeCase.spec.js similarity index 100% rename from snakeCase/snakeCase.spec.js rename to archived_snakeCase/snakeCase.spec.js diff --git a/snakeCase/solution/snakeCase-solution.js b/archived_snakeCase/solution/snakeCase-solution.js similarity index 100% rename from snakeCase/solution/snakeCase-solution.js rename to archived_snakeCase/solution/snakeCase-solution.js diff --git a/archived_snakeCase/solution/snakeCase-solution.spec.js b/archived_snakeCase/solution/snakeCase-solution.spec.js new file mode 100644 index 0000000..37cd499 --- /dev/null +++ b/archived_snakeCase/solution/snakeCase-solution.spec.js @@ -0,0 +1,26 @@ +const snakeCase = require('./snakeCase-solution'); + +describe('snakeCase', () => { + test('works with simple lowercased phrases', () => { + expect(snakeCase('hello world')).toEqual('hello_world'); + }); + test.skip('works with Caps and punctuation', () => { + expect(snakeCase('Hello, World???')).toEqual('hello_world'); + }); + test.skip('works with longer phrases', () => { + expect(snakeCase('This is the song that never ends....')).toEqual( + 'this_is_the_song_that_never_ends' + ); + }); + test.skip('works with camel case', () => { + expect(snakeCase('snakeCase')).toEqual('snake_case'); + }); + test.skip('works with kebab case', () => { + expect(snakeCase('snake-case')).toEqual('snake_case'); + }); + test.skip('works with WTF case', () => { + expect(snakeCase('SnAkE..CaSe..Is..AwEsOmE')).toEqual( + 'snake_case_is_awesome' + ); + }); +}); diff --git a/snakeCase/solution/snakeCase-solution.spec.js b/snakeCase/solution/snakeCase-solution.spec.js deleted file mode 100644 index b8620a2..0000000 --- a/snakeCase/solution/snakeCase-solution.spec.js +++ /dev/null @@ -1,26 +0,0 @@ -const snakeCase = require("./snakeCase"); - -describe("snakeCase", () => { - test("works with simple lowercased phrases", () => { - expect(snakeCase("hello world")).toEqual("hello_world"); - }); - test.skip("works with Caps and punctuation", () => { - expect(snakeCase("Hello, World???")).toEqual("hello_world"); - }); - test.skip("works with longer phrases", () => { - expect(snakeCase("This is the song that never ends....")).toEqual( - "this_is_the_song_that_never_ends" - ); - }); - test.skip("works with camel case", () => { - expect(snakeCase("snakeCase")).toEqual("snake_case"); - }); - test.skip("works with kebab case", () => { - expect(snakeCase("snake-case")).toEqual("snake_case"); - }); - test.skip("works with WTF case", () => { - expect(snakeCase("SnAkE..CaSe..Is..AwEsOmE")).toEqual( - "snake_case_is_awesome" - ); - }); -}); From e416717ba93a5ecf5ca055e88329996e2be65f3f Mon Sep 17 00:00:00 2001 From: thatblindgeye Date: Wed, 1 Feb 2023 18:58:58 -0500 Subject: [PATCH 4/7] Remove test skips for solutions --- .../solution/repeatString-solution.spec.js | 12 ++++---- .../solution/reverseString-solution.spec.js | 6 ++-- .../solution/removeFromArray-solution.spec.js | 12 ++++---- 05_sumAll/solution/sumAll-solution.spec.js | 12 ++++---- .../solution/leapYears-solution.spec.js | 10 +++---- .../solution/tempConversion-solution.spec.js | 10 +++---- .../solution/calculator-solution.spec.js | 30 +++++++++---------- .../solution/palindromes-solution.spec.js | 10 +++---- .../solution/fibonacci-solution.spec.js | 16 +++++----- .../solution/findTheOldest-solution.spec.js | 4 +-- 13_caesar/solution/caesar-solution.spec.js | 12 ++++---- .../solution/pigLatin-solution.spec.js | 16 +++++----- .../solution/snakeCase-solution.spec.js | 10 +++---- 13 files changed, 80 insertions(+), 80 deletions(-) diff --git a/02_repeatString/solution/repeatString-solution.spec.js b/02_repeatString/solution/repeatString-solution.spec.js index 417e14f..c506ce1 100644 --- a/02_repeatString/solution/repeatString-solution.spec.js +++ b/02_repeatString/solution/repeatString-solution.spec.js @@ -4,19 +4,19 @@ describe('repeatString', () => { test('repeats the string', () => { expect(repeatString('hey', 3)).toEqual('heyheyhey'); }); - test.skip('repeats the string many times', () => { + test('repeats the string many times', () => { expect(repeatString('hey', 10)).toEqual('heyheyheyheyheyheyheyheyheyhey'); }); - test.skip('repeats the string 1 times', () => { + test('repeats the string 1 times', () => { expect(repeatString('hey', 1)).toEqual('hey'); }); - test.skip('repeats the string 0 times', () => { + test('repeats the string 0 times', () => { expect(repeatString('hey', 0)).toEqual(''); }); - test.skip('returns ERROR with negative numbers', () => { + test('returns ERROR with negative numbers', () => { expect(repeatString('hey', -1)).toEqual('ERROR'); }); - test.skip('repeats the string a random amount of times', function () { + test('repeats the string a random amount of times', function () { /*The number is generated by using Math.random to get a value from between 0 to 1, when this is multiplied by 1000 and rounded down with Math.floor it equals a number between 0 to 999 (this number will change everytime you run @@ -33,7 +33,7 @@ describe('repeatString', () => { number ); }); - test.skip('works with blank strings', () => { + test('works with blank strings', () => { expect(repeatString('', 10)).toEqual(''); }); }); diff --git a/03_reverseString/solution/reverseString-solution.spec.js b/03_reverseString/solution/reverseString-solution.spec.js index 5ed33a1..629e071 100644 --- a/03_reverseString/solution/reverseString-solution.spec.js +++ b/03_reverseString/solution/reverseString-solution.spec.js @@ -5,14 +5,14 @@ describe('reverseString', () => { expect(reverseString('hello')).toEqual('olleh'); }); - test.skip('reverses multiple words', () => { + test('reverses multiple words', () => { expect(reverseString('hello there')).toEqual('ereht olleh'); }); - test.skip('works with numbers and punctuation', () => { + test('works with numbers and punctuation', () => { expect(reverseString('123! abc!')).toEqual('!cba !321'); }); - test.skip('works with blank strings', () => { + test('works with blank strings', () => { expect(reverseString('')).toEqual(''); }); }); diff --git a/04_removeFromArray/solution/removeFromArray-solution.spec.js b/04_removeFromArray/solution/removeFromArray-solution.spec.js index 1916d98..ed03e08 100644 --- a/04_removeFromArray/solution/removeFromArray-solution.spec.js +++ b/04_removeFromArray/solution/removeFromArray-solution.spec.js @@ -4,22 +4,22 @@ describe('removeFromArray', () => { test('removes a single value', () => { expect(removeFromArray([1, 2, 3, 4], 3)).toEqual([1, 2, 4]); }); - test.skip('removes multiple values', () => { + test('removes multiple values', () => { expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]); }); - test.skip('ignores non present values', () => { + test('ignores non present values', () => { expect(removeFromArray([1, 2, 3, 4], 7, 'tacos')).toEqual([1, 2, 3, 4]); }); - test.skip('ignores non present values, but still works', () => { + test('ignores non present values, but still works', () => { expect(removeFromArray([1, 2, 3, 4], 7, 2)).toEqual([1, 3, 4]); }); - test.skip('can remove all values', () => { + test('can remove all values', () => { expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toEqual([]); }); - test.skip('works with strings', () => { + test('works with strings', () => { expect(removeFromArray(['hey', 2, 3, 'ho'], 'hey', 3)).toEqual([2, 'ho']); }); - test.skip('only removes same type', () => { + test('only removes same type', () => { expect(removeFromArray([1, 2, 3], '1', 3)).toEqual([1, 2]); }); }); diff --git a/05_sumAll/solution/sumAll-solution.spec.js b/05_sumAll/solution/sumAll-solution.spec.js index 8cd9826..c78ae4e 100644 --- a/05_sumAll/solution/sumAll-solution.spec.js +++ b/05_sumAll/solution/sumAll-solution.spec.js @@ -4,22 +4,22 @@ describe('sumAll', () => { test('sums numbers within the range', () => { expect(sumAll(1, 4)).toEqual(10); }); - test.skip('works with large numbers', () => { + test('works with large numbers', () => { expect(sumAll(1, 4000)).toEqual(8002000); }); - test.skip('works with larger number first', () => { + test('works with larger number first', () => { expect(sumAll(123, 1)).toEqual(7626); }); - test.skip('returns ERROR with negative numbers', () => { + test('returns ERROR with negative numbers', () => { expect(sumAll(-10, 4)).toEqual('ERROR'); }); - test.skip('returns ERROR with non-integer parameters', () => { + test('returns ERROR with non-integer parameters', () => { expect(sumAll(2.5, 4)).toEqual('ERROR'); }); - test.skip('returns ERROR with non-number parameters', () => { + test('returns ERROR with non-number parameters', () => { expect(sumAll(10, '90')).toEqual('ERROR'); }); - test.skip('returns ERROR with non-number parameters', () => { + test('returns ERROR with non-number parameters', () => { expect(sumAll(10, [90, 1])).toEqual('ERROR'); }); }); diff --git a/06_leapYears/solution/leapYears-solution.spec.js b/06_leapYears/solution/leapYears-solution.spec.js index 3afd656..19f639e 100644 --- a/06_leapYears/solution/leapYears-solution.spec.js +++ b/06_leapYears/solution/leapYears-solution.spec.js @@ -4,19 +4,19 @@ describe('leapYears', () => { test('works with non century years', () => { expect(leapYears(1996)).toBe(true); }); - test.skip('works with non century years', () => { + test('works with non century years', () => { expect(leapYears(1997)).toBe(false); }); - test.skip('works with ridiculously futuristic non century years', () => { + test('works with ridiculously futuristic non century years', () => { expect(leapYears(34992)).toBe(true); }); - test.skip('works with century years', () => { + test('works with century years', () => { expect(leapYears(1900)).toBe(false); }); - test.skip('works with century years', () => { + test('works with century years', () => { expect(leapYears(1600)).toBe(true); }); - test.skip('works with century years', () => { + test('works with century years', () => { expect(leapYears(700)).toBe(false); }); }); diff --git a/07_tempConversion/solution/tempConversion-solution.spec.js b/07_tempConversion/solution/tempConversion-solution.spec.js index 27a840a..09b8faf 100644 --- a/07_tempConversion/solution/tempConversion-solution.spec.js +++ b/07_tempConversion/solution/tempConversion-solution.spec.js @@ -7,22 +7,22 @@ describe('convertToCelsius', () => { test('works', () => { expect(convertToCelsius(32)).toEqual(0); }); - test.skip('rounds to 1 decimal', () => { + test('rounds to 1 decimal', () => { expect(convertToCelsius(100)).toEqual(37.8); }); - test.skip('works with negatives', () => { + test('works with negatives', () => { expect(convertToCelsius(-100)).toEqual(-73.3); }); }); describe('convertToFahrenheit', () => { - test.skip('works', () => { + test('works', () => { expect(convertToFahrenheit(0)).toEqual(32); }); - test.skip('rounds to 1 decimal', () => { + test('rounds to 1 decimal', () => { expect(convertToFahrenheit(73.2)).toEqual(163.8); }); - test.skip('works with negatives', () => { + test('works with negatives', () => { expect(convertToFahrenheit(-10)).toEqual(14); }); }); diff --git a/08_calculator/solution/calculator-solution.spec.js b/08_calculator/solution/calculator-solution.spec.js index 0e1090c..453707c 100644 --- a/08_calculator/solution/calculator-solution.spec.js +++ b/08_calculator/solution/calculator-solution.spec.js @@ -5,73 +5,73 @@ describe('add', () => { expect(calculator.add(0, 0)).toBe(0); }); - test.skip('adds 2 and 2', () => { + test('adds 2 and 2', () => { expect(calculator.add(2, 2)).toBe(4); }); - test.skip('adds positive numbers', () => { + test('adds positive numbers', () => { expect(calculator.add(2, 6)).toBe(8); }); }); describe('subtract', () => { - test.skip('subtracts numbers', () => { + test('subtracts numbers', () => { expect(calculator.subtract(10, 4)).toBe(6); }); }); describe('sum', () => { - test.skip('computes the sum of an empty array', () => { + test('computes the sum of an empty array', () => { expect(calculator.sum([])).toBe(0); }); - test.skip('computes the sum of an array of one number', () => { + test('computes the sum of an array of one number', () => { expect(calculator.sum([7])).toBe(7); }); - test.skip('computes the sum of an array of two numbers', () => { + test('computes the sum of an array of two numbers', () => { expect(calculator.sum([7, 11])).toBe(18); }); - test.skip('computes the sum of an array of many numbers', () => { + test('computes the sum of an array of many numbers', () => { expect(calculator.sum([1, 3, 5, 7, 9])).toBe(25); }); }); describe('multiply', () => { - test.skip('multiplies two numbers', () => { + test('multiplies two numbers', () => { expect(calculator.multiply([2, 4])).toBe(8); }); - test.skip('multiplies several numbers', () => { + test('multiplies several numbers', () => { expect(calculator.multiply([2, 4, 6, 8, 10, 12, 14])).toBe(645120); }); }); describe('power', () => { - test.skip('raises one number to the power of another number', () => { + test('raises one number to the power of another number', () => { expect(calculator.power(4, 3)).toBe(64); // 4 to third power is 64 }); }); describe('factorial', () => { - test.skip('computes the factorial of 0', () => { + test('computes the factorial of 0', () => { expect(calculator.factorial(0)).toBe(1); // 0! = 1 }); - test.skip('computes the factorial of 1', () => { + test('computes the factorial of 1', () => { expect(calculator.factorial(1)).toBe(1); }); - test.skip('computes the factorial of 2', () => { + test('computes the factorial of 2', () => { expect(calculator.factorial(2)).toBe(2); }); - test.skip('computes the factorial of 5', () => { + test('computes the factorial of 5', () => { expect(calculator.factorial(5)).toBe(120); }); - test.skip('computes the factorial of 10', () => { + test('computes the factorial of 10', () => { expect(calculator.factorial(10)).toBe(3628800); }); }); diff --git a/09_palindromes/solution/palindromes-solution.spec.js b/09_palindromes/solution/palindromes-solution.spec.js index b1f5d41..c2538aa 100644 --- a/09_palindromes/solution/palindromes-solution.spec.js +++ b/09_palindromes/solution/palindromes-solution.spec.js @@ -4,21 +4,21 @@ describe('palindromes', () => { test('works with single words', () => { expect(palindromes('racecar')).toBe(true); }); - test.skip('works with punctuation ', () => { + test('works with punctuation ', () => { expect(palindromes('racecar!')).toBe(true); }); - test.skip('works with upper-case letters ', () => { + test('works with upper-case letters ', () => { expect(palindromes('Racecar!')).toBe(true); }); - test.skip('works with multiple words', () => { + test('works with multiple words', () => { expect(palindromes('A car, a man, a maraca.')).toBe(true); }); - test.skip('works with multiple words', () => { + test('works with multiple words', () => { expect(palindromes('Animal loots foliated detail of stool lamina.')).toBe( true ); }); - test.skip("doesn't just always return true", () => { + test("doesn't just always return true", () => { expect(palindromes('ZZZZ car, a man, a maraca.')).toBe(false); }); }); diff --git a/10_fibonacci/solution/fibonacci-solution.spec.js b/10_fibonacci/solution/fibonacci-solution.spec.js index abc6ffd..89de463 100644 --- a/10_fibonacci/solution/fibonacci-solution.spec.js +++ b/10_fibonacci/solution/fibonacci-solution.spec.js @@ -4,28 +4,28 @@ describe('fibonacci', () => { test('4th fibonacci number is 3', () => { expect(fibonacci(4)).toBe(3); }); - test.skip('6th fibonacci number is 8', () => { + test('6th fibonacci number is 8', () => { expect(fibonacci(6)).toBe(8); }); - test.skip('10th fibonacci number is 55', () => { + test('10th fibonacci number is 55', () => { expect(fibonacci(10)).toBe(55); }); - test.skip('15th fibonacci number is 610', () => { + test('15th fibonacci number is 610', () => { expect(fibonacci(15)).toBe(610); }); - test.skip('25th fibonacci number is 75025', () => { + test('25th fibonacci number is 75025', () => { expect(fibonacci(25)).toBe(75025); }); - test.skip("doesn't accept negatives", () => { + test("doesn't accept negatives", () => { expect(fibonacci(-25)).toBe('OOPS'); }); - test.skip('DOES accept strings', () => { + test('DOES accept strings', () => { expect(fibonacci('1')).toBe(1); }); - test.skip('DOES accept strings', () => { + test('DOES accept strings', () => { expect(fibonacci('2')).toBe(1); }); - test.skip('DOES accept strings', () => { + test('DOES accept strings', () => { expect(fibonacci('8')).toBe(21); }); }); diff --git a/12_findTheOldest/solution/findTheOldest-solution.spec.js b/12_findTheOldest/solution/findTheOldest-solution.spec.js index 9b47c12..c92550c 100644 --- a/12_findTheOldest/solution/findTheOldest-solution.spec.js +++ b/12_findTheOldest/solution/findTheOldest-solution.spec.js @@ -21,7 +21,7 @@ describe('findTheOldest', () => { ]; expect(findTheOldest(people).name).toBe('Ray'); }); - test.skip('finds the oldest person if someone is still living', () => { + test('finds the oldest person if someone is still living', () => { const people = [ { name: 'Carly', @@ -40,7 +40,7 @@ describe('findTheOldest', () => { ]; expect(findTheOldest(people).name).toBe('Ray'); }); - test.skip('finds the oldest person if the OLDEST is still living', () => { + test('finds the oldest person if the OLDEST is still living', () => { const people = [ { name: 'Carly', diff --git a/13_caesar/solution/caesar-solution.spec.js b/13_caesar/solution/caesar-solution.spec.js index 55e3852..383b1dc 100644 --- a/13_caesar/solution/caesar-solution.spec.js +++ b/13_caesar/solution/caesar-solution.spec.js @@ -3,21 +3,21 @@ const caesar = require('./caesar-solution'); test('works with single letters', () => { expect(caesar('A', 1)).toBe('B'); }); -test.skip('works with words', () => { +test('works with words', () => { expect(caesar('Aaa', 1)).toBe('Bbb'); }); -test.skip('works with phrases', () => { +test('works with phrases', () => { expect(caesar('Hello, World!', 5)).toBe('Mjqqt, Btwqi!'); }); -test.skip('works with negative shift', () => { +test('works with negative shift', () => { expect(caesar('Mjqqt, Btwqi!', -5)).toBe('Hello, World!'); }); -test.skip('wraps', () => { +test('wraps', () => { expect(caesar('Z', 1)).toBe('A'); }); -test.skip('works with large shift factors', () => { +test('works with large shift factors', () => { expect(caesar('Hello, World!', 75)).toBe('Ebiil, Tloia!'); }); -test.skip('works with large negative shift factors', () => { +test('works with large negative shift factors', () => { expect(caesar('Hello, World!', -29)).toBe('Ebiil, Tloia!'); }); diff --git a/archived_pigLatin/solution/pigLatin-solution.spec.js b/archived_pigLatin/solution/pigLatin-solution.spec.js index dbcd5a1..9e535a1 100644 --- a/archived_pigLatin/solution/pigLatin-solution.spec.js +++ b/archived_pigLatin/solution/pigLatin-solution.spec.js @@ -22,35 +22,35 @@ describe('translate', () => { expect(pigLatin('apple')).toBe('appleay'); }); - test.skip('translates a word beginning with a consonant', () => { + test('translates a word beginning with a consonant', () => { expect(pigLatin('banana')).toBe('ananabay'); }); - test.skip('translates a word beginning with two consonants', () => { + test('translates a word beginning with two consonants', () => { expect(pigLatin('cherry')).toBe('errychay'); }); - test.skip('translates two words', () => { + test('translates two words', () => { expect(pigLatin('eat pie')).toBe('eatay iepay'); }); - test.skip('translates a word beginning with three consonants', () => { + test('translates a word beginning with three consonants', () => { expect(pigLatin('three')).toBe('eethray'); }); - test.skip('counts "sch" as a single phoneme', () => { + test('counts "sch" as a single phoneme', () => { expect(pigLatin('school')).toBe('oolschay'); }); - test.skip('counts "qu" as a single phoneme', () => { + test('counts "qu" as a single phoneme', () => { expect(pigLatin('quiet')).toBe('ietquay'); }); - test.skip('counts "qu" as a consonant even when its preceded by a consonant', () => { + test('counts "qu" as a consonant even when its preceded by a consonant', () => { expect(pigLatin('square')).toBe('aresquay'); }); - test.skip('translates many words', () => { + test('translates many words', () => { expect(pigLatin('the quick brown fox')).toBe('ethay ickquay ownbray oxfay'); }); }); diff --git a/archived_snakeCase/solution/snakeCase-solution.spec.js b/archived_snakeCase/solution/snakeCase-solution.spec.js index 37cd499..c3f2048 100644 --- a/archived_snakeCase/solution/snakeCase-solution.spec.js +++ b/archived_snakeCase/solution/snakeCase-solution.spec.js @@ -4,21 +4,21 @@ describe('snakeCase', () => { test('works with simple lowercased phrases', () => { expect(snakeCase('hello world')).toEqual('hello_world'); }); - test.skip('works with Caps and punctuation', () => { + test('works with Caps and punctuation', () => { expect(snakeCase('Hello, World???')).toEqual('hello_world'); }); - test.skip('works with longer phrases', () => { + test('works with longer phrases', () => { expect(snakeCase('This is the song that never ends....')).toEqual( 'this_is_the_song_that_never_ends' ); }); - test.skip('works with camel case', () => { + test('works with camel case', () => { expect(snakeCase('snakeCase')).toEqual('snake_case'); }); - test.skip('works with kebab case', () => { + test('works with kebab case', () => { expect(snakeCase('snake-case')).toEqual('snake_case'); }); - test.skip('works with WTF case', () => { + test('works with WTF case', () => { expect(snakeCase('SnAkE..CaSe..Is..AwEsOmE')).toEqual( 'snake_case_is_awesome' ); From 99d0e8a71a4e7da779cce48435ddeda8dc8077b4 Mon Sep 17 00:00:00 2001 From: 01zulfi <85733202+01zulfi@users.noreply.github.com> Date: Mon, 20 Feb 2023 19:10:10 +0500 Subject: [PATCH 5/7] Add circleci config file * We can use circleci to test all spec files in solution subdirectories --- .circleci/config.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..1471668 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,20 @@ +version: 2.1 + +orbs: + node: circleci/node@5.1.0 + +jobs: + test-solutions: + executor: node/default + steps: + - checkout + - node/install-packages: + pkg-manager: npm + - run: + command: npm run test solution + name: Run tests in **/solution/*.spec.js + +workflows: + test-solutions: + jobs: + - test-solutions From 6f5f71ff5b2540918d9a11604782c159fd3908c3 Mon Sep 17 00:00:00 2001 From: jhylacey <121734574+jhylacey@users.noreply.github.com> Date: Sat, 18 Mar 2023 14:14:44 -0500 Subject: [PATCH 6/7] Remove redundant wording in reverse string README --- 03_reverseString/README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/03_reverseString/README.md b/03_reverseString/README.md index 05221ae..692d755 100644 --- a/03_reverseString/README.md +++ b/03_reverseString/README.md @@ -6,7 +6,5 @@ Pretty simple, write a function called `reverseString` that returns its input, r reverseString('hello there') // returns 'ereht olleh' ``` -You will notice in this exercise that there are multiple tests, after making the first one pass, enable the others one by one by deleting the `.skip` in front the `test.skip()` function. - ## Hints Strings in JavaScript cannot be reversed directly so you're going to have to split it into something else first.. do the reversal and then join it back together into a string. From 75869d191224f0a5996c10a85dc3199152813483 Mon Sep 17 00:00:00 2001 From: Asartea <76259120+Asartea@users.noreply.github.com> Date: Sat, 18 Mar 2023 22:45:37 +0100 Subject: [PATCH 7/7] Mark caesar as archived and move archived exercise to own folder (#336) --- {13_caesar => archive/archived_caesar}/README.md | 0 {13_caesar => archive/archived_caesar}/caesar.js | 0 {13_caesar => archive/archived_caesar}/caesar.spec.js | 0 .../archived_caesar}/solution/caesar-solution.js | 0 .../archived_caesar}/solution/caesar-solution.spec.js | 0 {archived_pigLatin => archive/archived_pigLatin}/README.md | 0 {archived_pigLatin => archive/archived_pigLatin}/pigLatin.js | 0 {archived_pigLatin => archive/archived_pigLatin}/pigLatin.spec.js | 0 .../archived_pigLatin}/solution/pigLatin-solution.js | 0 .../archived_pigLatin}/solution/pigLatin-solution.spec.js | 0 {archived_snakeCase => archive/archived_snakeCase}/README.md | 0 {archived_snakeCase => archive/archived_snakeCase}/snakeCase.js | 0 .../archived_snakeCase}/snakeCase.spec.js | 0 .../archived_snakeCase}/solution/snakeCase-solution.js | 0 .../archived_snakeCase}/solution/snakeCase-solution.spec.js | 0 15 files changed, 0 insertions(+), 0 deletions(-) rename {13_caesar => archive/archived_caesar}/README.md (100%) rename {13_caesar => archive/archived_caesar}/caesar.js (100%) rename {13_caesar => archive/archived_caesar}/caesar.spec.js (100%) rename {13_caesar => archive/archived_caesar}/solution/caesar-solution.js (100%) rename {13_caesar => archive/archived_caesar}/solution/caesar-solution.spec.js (100%) rename {archived_pigLatin => archive/archived_pigLatin}/README.md (100%) rename {archived_pigLatin => archive/archived_pigLatin}/pigLatin.js (100%) rename {archived_pigLatin => archive/archived_pigLatin}/pigLatin.spec.js (100%) rename {archived_pigLatin => archive/archived_pigLatin}/solution/pigLatin-solution.js (100%) rename {archived_pigLatin => archive/archived_pigLatin}/solution/pigLatin-solution.spec.js (100%) rename {archived_snakeCase => archive/archived_snakeCase}/README.md (100%) rename {archived_snakeCase => archive/archived_snakeCase}/snakeCase.js (100%) rename {archived_snakeCase => archive/archived_snakeCase}/snakeCase.spec.js (100%) rename {archived_snakeCase => archive/archived_snakeCase}/solution/snakeCase-solution.js (100%) rename {archived_snakeCase => archive/archived_snakeCase}/solution/snakeCase-solution.spec.js (100%) diff --git a/13_caesar/README.md b/archive/archived_caesar/README.md similarity index 100% rename from 13_caesar/README.md rename to archive/archived_caesar/README.md diff --git a/13_caesar/caesar.js b/archive/archived_caesar/caesar.js similarity index 100% rename from 13_caesar/caesar.js rename to archive/archived_caesar/caesar.js diff --git a/13_caesar/caesar.spec.js b/archive/archived_caesar/caesar.spec.js similarity index 100% rename from 13_caesar/caesar.spec.js rename to archive/archived_caesar/caesar.spec.js diff --git a/13_caesar/solution/caesar-solution.js b/archive/archived_caesar/solution/caesar-solution.js similarity index 100% rename from 13_caesar/solution/caesar-solution.js rename to archive/archived_caesar/solution/caesar-solution.js diff --git a/13_caesar/solution/caesar-solution.spec.js b/archive/archived_caesar/solution/caesar-solution.spec.js similarity index 100% rename from 13_caesar/solution/caesar-solution.spec.js rename to archive/archived_caesar/solution/caesar-solution.spec.js diff --git a/archived_pigLatin/README.md b/archive/archived_pigLatin/README.md similarity index 100% rename from archived_pigLatin/README.md rename to archive/archived_pigLatin/README.md diff --git a/archived_pigLatin/pigLatin.js b/archive/archived_pigLatin/pigLatin.js similarity index 100% rename from archived_pigLatin/pigLatin.js rename to archive/archived_pigLatin/pigLatin.js diff --git a/archived_pigLatin/pigLatin.spec.js b/archive/archived_pigLatin/pigLatin.spec.js similarity index 100% rename from archived_pigLatin/pigLatin.spec.js rename to archive/archived_pigLatin/pigLatin.spec.js diff --git a/archived_pigLatin/solution/pigLatin-solution.js b/archive/archived_pigLatin/solution/pigLatin-solution.js similarity index 100% rename from archived_pigLatin/solution/pigLatin-solution.js rename to archive/archived_pigLatin/solution/pigLatin-solution.js diff --git a/archived_pigLatin/solution/pigLatin-solution.spec.js b/archive/archived_pigLatin/solution/pigLatin-solution.spec.js similarity index 100% rename from archived_pigLatin/solution/pigLatin-solution.spec.js rename to archive/archived_pigLatin/solution/pigLatin-solution.spec.js diff --git a/archived_snakeCase/README.md b/archive/archived_snakeCase/README.md similarity index 100% rename from archived_snakeCase/README.md rename to archive/archived_snakeCase/README.md diff --git a/archived_snakeCase/snakeCase.js b/archive/archived_snakeCase/snakeCase.js similarity index 100% rename from archived_snakeCase/snakeCase.js rename to archive/archived_snakeCase/snakeCase.js diff --git a/archived_snakeCase/snakeCase.spec.js b/archive/archived_snakeCase/snakeCase.spec.js similarity index 100% rename from archived_snakeCase/snakeCase.spec.js rename to archive/archived_snakeCase/snakeCase.spec.js diff --git a/archived_snakeCase/solution/snakeCase-solution.js b/archive/archived_snakeCase/solution/snakeCase-solution.js similarity index 100% rename from archived_snakeCase/solution/snakeCase-solution.js rename to archive/archived_snakeCase/solution/snakeCase-solution.js diff --git a/archived_snakeCase/solution/snakeCase-solution.spec.js b/archive/archived_snakeCase/solution/snakeCase-solution.spec.js similarity index 100% rename from archived_snakeCase/solution/snakeCase-solution.spec.js rename to archive/archived_snakeCase/solution/snakeCase-solution.spec.js