From 3688261cb3522398a8a8429fea6740251439e6ac Mon Sep 17 00:00:00 2001 From: Manny-Ellegood10 Date: Tue, 23 Feb 2021 18:00:38 -0500 Subject: [PATCH 1/2] completed 6 of 8 test --- Day01/Problem01.js | 45 ++++++++++++++++++++++++++++++++--------- Day01/Problem01.test.js | 3 ++- package.json | 2 +- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/Day01/Problem01.js b/Day01/Problem01.js index 6ad3c39..aa2bee4 100644 --- a/Day01/Problem01.js +++ b/Day01/Problem01.js @@ -6,8 +6,8 @@ class Problem { * separated by single spaces. */ wordCount(input) { - // code goes here - return null; + // we want to split up each word with a space and get the length. + return input.split(' ').length; } @@ -16,8 +16,14 @@ class Problem { letter of each word. Words will be separated by only one space. * */ - letterCapitalize(str) { - return null; + letterCapitalize(input) { + // first we have to capitalize the first letter of the first word + // using slice and setting it to lowercase will lower case the rest of the word. + let capitalizeString = (str) => str[0].toUpperCase() + str.slice(1).toLowerCase(); + // Then we have to split up all the words entered into an array + let words = input.split(' ').map(capitalizeString); + let capitalizeAllBeginningLetters = words.join(' '); + return capitalizeAllBeginningLetters; } @@ -29,7 +35,12 @@ class Problem { */ firstReverse(input){ - return null; + // we need to convert the input into an array + let word = input.split(' '); + // now we have to use the reverse function on the array + let reverseStr = word.reverse(); + // return the reversed array + return reverseStr; } /** @@ -39,8 +50,20 @@ class Problem { * input will not be empty. */ longestWord(input) { - // code goes here - return null; + // convert input to an array + + input = input.replace(/[^0-9a-zA-Z ]/g, ''); + let word = input.split(' '); + // using the sort + + + + let sortArray = word.sort((strA, strB) => { + // the below will move up the largest string in the array and return the largest string inside the aray + return strB.length - strA.length; + }) + // we need to make sure we are returning the index of the array [0] for the first word + return sortArray[0]; } /** @@ -49,8 +72,12 @@ class Problem { * Let numbers and symbols stay the way they are. */ swapCase(str) { - // code goes here - return null; + // code goes her + const isUpperCase = (character) => character.toUpperCase() == character; + + return str.split(' ').map( word => { + return word.split('').map( c => isUpperCase(c) ? c.toLowerCase() : c.toUpperCase()).join('') + }).join(' '); } } diff --git a/Day01/Problem01.test.js b/Day01/Problem01.test.js index 3623ab2..c547372 100644 --- a/Day01/Problem01.test.js +++ b/Day01/Problem01.test.js @@ -100,4 +100,5 @@ test("swapCase test02", () => { let actual = problem.swapCase("Sup DUDE!!?"); expect(actual).toEqual(expected); -}); \ No newline at end of file +}); + diff --git a/package.json b/package.json index 7684e48..cb66578 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "36chambersofcode-js", "version": "1.0.0", "description": "", - "main": "index.js", + "main": "Problem01.js", "scripts": { "test": "jest" }, From 27adeeca3634f79d207756eaa057b836342d766f Mon Sep 17 00:00:00 2001 From: Manny-Ellegood10 Date: Tue, 23 Feb 2021 18:34:25 -0500 Subject: [PATCH 2/2] completed all 10 test --- Day01/Problem01.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Day01/Problem01.js b/Day01/Problem01.js index aa2bee4..23d10fb 100644 --- a/Day01/Problem01.js +++ b/Day01/Problem01.js @@ -36,9 +36,9 @@ class Problem { firstReverse(input){ // we need to convert the input into an array - let word = input.split(' '); + let word = input.split(''); // now we have to use the reverse function on the array - let reverseStr = word.reverse(); + let reverseStr = word.reverse().join(''); // return the reversed array return reverseStr; }