Skip to content
Open
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
39 changes: 32 additions & 7 deletions Day01/Problem01.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Problem {
*/
wordCount(input) {
// code goes here
return null;
return input.split(' ').length;
}


Expand All @@ -17,7 +17,14 @@ class Problem {
*
*/
letterCapitalize(str) {
return null;
let words = str.split(" ");

for (let i = 0; i < words.length; i++) {
words[i] = words[i][0].toUpperCase() + words[i].substr(1);
}

return words.join(" ");

}


Expand All @@ -29,7 +36,8 @@ class Problem {
*/

firstReverse(input){
return null;
return input.split("").reverse().join("");

}

/**
Expand All @@ -39,8 +47,17 @@ class Problem {
* input will not be empty.
*/
longestWord(input) {
// code goes here
return null;
let longest = "";
input = input.replace(/[^a-zA-Z0-9]/gi, " ");
input = input.split(" ");
for (let i = 0; i < input.length; i++) {
if (input[i].length > longest.length) {
longest = input[i];
}
}
return longest;
}
// code goes here//
}

/**
Expand All @@ -50,9 +67,17 @@ class Problem {
*/
swapCase(str) {
// code goes here
return null;
let newStr = "";
for (let i = 0; i < str.length; i++) {
if (str[i] === str[i].toLowerCase()) {
newStr += str[i].toUpperCase();
} else {
newStr += str[i].toLowerCase();
}
}
return newStr;

}

}

module.exports = Problem;