From 9735619e4e883e25c86461ab7663e90281e33b58 Mon Sep 17 00:00:00 2001 From: Adrienne Date: Mon, 22 Feb 2021 21:01:45 -0500 Subject: [PATCH 1/2] Problem01.js --- Day01/.loops.36.ques.js | 127 ++++++++++++++++++++++++++++++++++++++++ Day01/Problem01.js | 24 +++++++- 2 files changed, 148 insertions(+), 3 deletions(-) create mode 100644 Day01/.loops.36.ques.js diff --git a/Day01/.loops.36.ques.js b/Day01/.loops.36.ques.js new file mode 100644 index 0000000..9e39df6 --- /dev/null +++ b/Day01/.loops.36.ques.js @@ -0,0 +1,127 @@ +class Problem { + /** + * Have the wordCount(input) take the str string parameter being passed + * and return the number of words the string contains + * (e.g. "Never eat shredded wheat or cake" would return 6). Words will be + * separated by single spaces. + */ + wordCount(input) { + let wordCount = 0 + for () let i =0; i= 0; i--) { + newString += str[i]; + } + return newString; + } + reverseString('hello'); + + // firstReverse(input) { + // let splitString = input.split(''); + // let reverseArray = splitString.reverse(); + //let joinArray = reverseArray.join(''); + //return joinArray; + } + + + /** + * Have the longestWord(String input) take the input parameter being passed and return the + * largest word in the string. If there are two or more words that are the same length, + * return the first word from the string with that length. Ignore punctuation and assume + * input will not be empty. + */ + longestWord (input) + // let splitString = input.split(''); + // let Array = splitString.length (); + longestWord(input) { + // code goes here + let strSplit = input.split(''); + let longestWord = 0; + for (let i = 0; i < strSplit.length; i++){ + if(strSplit[i].length > longestWord){ + longestWord = strSplit[i].length; + } + } + return longestWord; + } + + return sen; + + } + + // keep this function call here + console.log(LongestWord(readline())); // code goes here + return null; + } + + /** + * 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) { + letterCapitalize(str) { + // create a variable to contain output + let output = "" + // create a loop to go through the string + for(let i = 0; i < str.length; i ++){ + // capitalize first index + if(i === 0){ + output += str[i].toUpperCase() + // add to variable + } + else if (str[i-1] === " "){ + // capitalize the index after each space + // add to variable + output += str[i].toUpperCase() + } + else { + output += str[i] + } + } + // return the output + return output; + } + + return null; + } + +} + +module.exports = Problem; + +letterCapitalize(string) { + + return string.replace(/\w\S*/g, (w) => (w.replace(/^\w/, (c) => c.toUpperCase()))); +} diff --git a/Day01/Problem01.js b/Day01/Problem01.js index 6ad3c39..6e3f915 100644 --- a/Day01/Problem01.js +++ b/Day01/Problem01.js @@ -6,8 +6,13 @@ class Problem { * separated by single spaces. */ wordCount(input) { - // code goes here - return null; + let wordCount = 0 + for () let i =0; i= 0; i--) { + if (i == reverseStr {i}) + reverseStr++; + ) + } + return reverseStr; } /** From 1af12dbbc9a88b0d846f5b9566bcf585e778e430 Mon Sep 17 00:00:00 2001 From: Adrienne Date: Wed, 3 Mar 2021 16:37:16 -0500 Subject: [PATCH 2/2] 36chamberscompleted --- Day01/.loops.36.ques.js | 32 +++++++++++++---- Day01/Problem01.js | 79 ++++++++++++++++++++++++++++------------- 2 files changed, 79 insertions(+), 32 deletions(-) diff --git a/Day01/.loops.36.ques.js b/Day01/.loops.36.ques.js index 9e39df6..9add973 100644 --- a/Day01/.loops.36.ques.js +++ b/Day01/.loops.36.ques.js @@ -5,14 +5,13 @@ class Problem { * (e.g. "Never eat shredded wheat or cake" would return 6). Words will be * separated by single spaces. */ - wordCount(input) { - let wordCount = 0 - for () let i =0; i { + let words = str.split(" "); + let size = 0; + let max = [" "]; + for (let i = 0; i < words.length; i++) { + if (words[i].length > size) { + size = words[i].length; + } + if (max[max.length - 1].length < words[i].length) { + max = []; + max.push(words[i]); + } else { + max = [...max, words[i]]; + } + } + return max; + }; + } return sen; diff --git a/Day01/Problem01.js b/Day01/Problem01.js index 6e3f915..47416f6 100644 --- a/Day01/Problem01.js +++ b/Day01/Problem01.js @@ -6,10 +6,13 @@ class Problem { * separated by single spaces. */ wordCount(input) { - let wordCount = 0 - for () let i =0; i= 0; i--) { - if (i == reverseStr {i}) - reverseStr++; - ) - } - return reverseStr; + let splitString = input.split(''); + let reverseArray = splitString.reverse(); + let joinArray = reverseArray.join(''); + return joinArray; } /** @@ -57,8 +71,17 @@ class Problem { * input will not be empty. */ longestWord(input) { - // code goes here - return null; + var str = input.split(/[^a-zA-Z]/); // splits string into words & ignores non-letters + var longest = 0; + var word = str; + for (var i = 0; i <= str.length - 1; i++) { // steps thru array & adjusts count to begin at 0 + if (longest < str[i].length) { // compares current longest with word in the array + longest = str[i].length; // longest word is replaced with new longest word + word = str[i]; // word is now the longest word + } + } + return word; + } } /** @@ -68,9 +91,15 @@ class Problem { */ swapCase(str) { // code goes here - return null; + var newLetters = ""; + for(var i = 0; i