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
54 changes: 47 additions & 7 deletions Day01/Problem01.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class Problem {
* separated by single spaces.
*/
wordCount(input) {
// code goes here
return null;
let words = input.split(' ');
return words.length; // code goes here
}


Expand All @@ -17,7 +17,13 @@ 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 +35,12 @@ class Problem {
*/

firstReverse(input){
return null;
let words = input.split('');
words.reverse();
// for ( let i = words.length ; i >= 0 ; i-- ) {
// reverse += words[i];
// };
return words.join('');
}

/**
Expand All @@ -40,7 +51,25 @@ class Problem {
*/
longestWord(input) {
// code goes here
return null;
input = input.replace(/[^a-zA-Z0-9]/gi, ' ');
let words = input.split(' ');
let longestLength = 0;
let longestWords = [];

for ( let i = 0 ; i < words.length ; i++ ) {
if ( words[i].length > longestLength ) {
longestLength = words[i].length;
}
};

for ( let i = 0 ; i < words.length ; i++ ) {
if (words[i].length === longestLength) {
longestWords.push(words[i]);
}
};


return longestWords[0];
}

/**
Expand All @@ -50,9 +79,20 @@ class Problem {
*/
swapCase(str) {
// code goes here
return null;
let swapped = "";
for ( var i = 0 ; i < str.length ; i++ ){

if ( str[i] === str[i].toLowerCase()){
swapped += str[i].toUpperCase();

} else {
swapped += str[i].toLowerCase();
}
}

return swapped;
}
}

}

module.exports = Problem;