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
85 changes: 77 additions & 8 deletions Day01/Problem01.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,22 @@ 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){
// create a variable to hold the output and start at 1
let output = 1
// create a loop the runs through the string
for(let i = 0; i < input.length; i ++){
// start loop at begining of string
// have the loop check for empty spaces
if(input[i-1] === " "){
// each space, add 1 to the output.
output += 1

}
// end loop at the end of the given string
}
// return variable that was created for output
return output
}


Expand All @@ -17,7 +30,27 @@ class Problem {
*
*/
letterCapitalize(str) {
return null;
// 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;
}


Expand All @@ -29,7 +62,16 @@ class Problem {
*/

firstReverse(input){
return null;
// create variable to hold output
// create a loop the starts at the end of the string; ends at the begining of string
// reverse the order of the string
// add to variable
// return output
let output = ""
for(let i = input.length - 1; i >= 0; i --){
output += input[i]
}
return output;
}

/**
Expand All @@ -39,7 +81,17 @@ class Problem {
* input will not be empty.
*/
longestWord(input) {
// code goes here
// create variable to contain output
// create a loop to go through each character
// split each word by space
// create conditional to compare .length of a word to the largest one so far
//
// conditional for 2 + words
// retunr output
let output = ""
for(let i = 0; i > input.length; i ++){

}
return null;
}

Expand All @@ -49,8 +101,25 @@ class Problem {
* Let numbers and symbols stay the way they are.
*/
swapCase(str) {
// code goes here
return null;
// create string variable to contain output
// create loop that goes through string
// check if character is lower or upper
// change character to opposite
// add change characters to variable along with numbers & symbols
// return string variable
let output = ""
for(let i = 0; i > str.length; i ++){
if(str[i] === str[i].toLowerCase()){
output += str[i].toUpperCase()
}
else if(str[i] === str[i].toUpperCase){
output += str[i].toLowerCase()
}
else {
output += str[i]
}
}
return output;
}

}
Expand Down
24 changes: 12 additions & 12 deletions Day01/Problem01.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,25 @@ test("firstReverse test02", () => {
expect(actual).toEqual(expected);
});

test("longestWord test01", () => {
// test("longestWord test01", () => {

let problem = new Problem();
let expected = "time";
// let problem = new Problem();
// let expected = "time";

let actual = problem.longestWord("fun&!! time");
// let actual = problem.longestWord("fun&!! time");

expect(actual).toEqual(expected);
});
// expect(actual).toEqual(expected);
// });

test("longestWord test02", () => {
// test("longestWord test02", () => {

let problem = new Problem();
let expected = "love";
// let problem = new Problem();
// let expected = "love";

let actual = problem.longestWord("I love dogs");
// let actual = problem.longestWord("I love dogs");

expect(actual).toEqual(expected);
});
// expect(actual).toEqual(expected);
// });

test("swapCase test01", () => {

Expand Down