From e57e78776c520c5aef739501500710133a387856 Mon Sep 17 00:00:00 2001 From: coopcool Date: Tue, 23 Feb 2021 00:30:42 -0500 Subject: [PATCH 1/2] 36chambersLAB --- Day01/Problem01.js | 70 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 16 deletions(-) diff --git a/Day01/Problem01.js b/Day01/Problem01.js index 6ad3c39..450fe26 100644 --- a/Day01/Problem01.js +++ b/Day01/Problem01.js @@ -5,21 +5,37 @@ class Problem { * (e.g. "Never eat shredded wheat or cake" would return 6). Words will be * separated by single spaces. */ - wordCount(input) { - // code goes here - return null; - } - + wordCount(input) { + //return input.split(' ').length; + const inputArr = input.split(' '); + return inputArr.length; + } + + //npm test + /** * Have the function LetterCapitalize(str) take the str parameter being passed and capitalize the first letter of each word. Words will be separated by only one space. * */ - letterCapitalize(str) { - return null; + letterCapitalize(str) { + + const userInput = str; + const wordsOnly = userInput.split(" "); + + for (let i = 0; i < wordsOnly.length; i++) { + wordsOnly[i] = wordsOnly[i][0].toUpperCase() + wordsOnly[i].substr(1); } + let newStr = wordsOnly.join(" "); + + return newStr; + } + + + + /** @@ -28,9 +44,12 @@ class Problem { * program should return the string sredoC dna dlroW olleH. */ - firstReverse(input){ - return null; - } + + firstReverse(input) { + + return input.split("").reverse().join(""); + } + /** * Have the longestWord(String input) take the input parameter being passed and return the @@ -39,20 +58,39 @@ class Problem { * input will not be empty. */ longestWord(input) { - // code goes here - return null; - } + var str = input.split(/[^A-Za-z]/); + var longest = 0; + var word = str; + for (var i = 0; i <= str.length - 1; i++) { + if (longest < str[i].length) { + longest = str[i].length; + word = str[i]; + } + } + return word; + } + /** * Have the swapCase(String input) take the input parameter and swap the case of each * character. For example: if str is "Hello World" the output should be hELLO wORLD. * Let numbers and symbols stay the way they are. */ - swapCase(str) { - // code goes here - return null; + swapCase(str) { + let newString = ""; + for (let i = 0; i < str.length; i++) { + if (str[i] === str[i].toLowerCase()) { + newString += str[i].toUpperCase(); + } else { + newString += str[i].toLowerCase(); + } + } + + return newString; + } } + module.exports = Problem; \ No newline at end of file From 1e17beb1d5dd1c6547937c98e985f8855853a232 Mon Sep 17 00:00:00 2001 From: coopcool Date: Tue, 23 Feb 2021 00:47:59 -0500 Subject: [PATCH 2/2] 36chambersLAB --- Day01/Problem01.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Day01/Problem01.js b/Day01/Problem01.js index 450fe26..420c8b2 100644 --- a/Day01/Problem01.js +++ b/Day01/Problem01.js @@ -69,7 +69,21 @@ class Problem { } return word; } - + //let regex = /([^A-Z a-z])+/g; + //let text = input.replace(regex, "").split(" "); + // let longestText = ""; + //let longestCount = 0; + + //for(let i = 0; i < text.length; i++){ + // if(text[i].length > longestCount){ + // longestCount = text[i].length; + // longestText = text[i]; + + //} + ///return longestText; + //} + // } + /** * Have the swapCase(String input) take the input parameter and swap the case of each