Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
62 changes: 44 additions & 18 deletions Day01/Problem01.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,28 @@ 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;
let string = input.split(' ');
let wordLength = string.length;
return wordLength;
}


/**
* 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) {
let output = ""
for(let i = 0; i < str.length; i ++){
if(i === 0){
output += str[i].toUpperCase()
}
else if (str[i-1] === " "){
output += str[i].toUpperCase()
}
else {
output += str[i]
}
}


return output;
}

/**
* Have the function firstReverse(String input) take the input parameter being passed and
Expand All @@ -29,7 +35,10 @@ class Problem {
*/

firstReverse(input){
return null;
let splitString = input.split('');
let reverseArray = splitString.reverse();
let joinArray = reverseArray.join('');
return joinArray;
}

/**
Expand All @@ -38,21 +47,38 @@ class Problem {
* return the first word from the string with that length. Ignore punctuation and assume
* 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;
}

/**
* 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;
var newLetters = "";
for ( var i = 0; i < str.length; i++ ) {
if ( str[i] === str[i].toLowerCase() ) {
newLetters += str[i].toUpperCase();
} else {
newLetters += str[i].toLowerCase();
}
}
console.log(newLetters);
return newLetters;
}

}

module.exports = Problem;
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
"license": "ISC",
"devDependencies": {
"jest": "^26.4.2"
},
"dependencies": {
"test": "^0.6.0"
}
}