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
45 changes: 36 additions & 9 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;
// we want to split up each word with a space and get the length.
return input.split(' ').length;
}


Expand All @@ -16,8 +16,14 @@ class Problem {
letter of each word. Words will be separated by only one space.
*
*/
letterCapitalize(str) {
return null;
letterCapitalize(input) {
// first we have to capitalize the first letter of the first word
// using slice and setting it to lowercase will lower case the rest of the word.
let capitalizeString = (str) => str[0].toUpperCase() + str.slice(1).toLowerCase();
// Then we have to split up all the words entered into an array
let words = input.split(' ').map(capitalizeString);
let capitalizeAllBeginningLetters = words.join(' ');
return capitalizeAllBeginningLetters;
}


Expand All @@ -29,7 +35,12 @@ class Problem {
*/

firstReverse(input){
return null;
// we need to convert the input into an array
let word = input.split('');
// now we have to use the reverse function on the array
let reverseStr = word.reverse().join('');
// return the reversed array
return reverseStr;
}

/**
Expand All @@ -39,8 +50,20 @@ class Problem {
* input will not be empty.
*/
longestWord(input) {
// code goes here
return null;
// convert input to an array

input = input.replace(/[^0-9a-zA-Z ]/g, '');
let word = input.split(' ');
// using the sort



let sortArray = word.sort((strA, strB) => {
// the below will move up the largest string in the array and return the largest string inside the aray
return strB.length - strA.length;
})
// we need to make sure we are returning the index of the array [0] for the first word
return sortArray[0];
}

/**
Expand All @@ -49,8 +72,12 @@ class Problem {
* Let numbers and symbols stay the way they are.
*/
swapCase(str) {
// code goes here
return null;
// code goes her
const isUpperCase = (character) => character.toUpperCase() == character;

return str.split(' ').map( word => {
return word.split('').map( c => isUpperCase(c) ? c.toLowerCase() : c.toUpperCase()).join('')
}).join(' ');
}

}
Expand Down
3 changes: 2 additions & 1 deletion Day01/Problem01.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,5 @@ test("swapCase test02", () => {
let actual = problem.swapCase("Sup DUDE!!?");

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "36chambersofcode-js",
"version": "1.0.0",
"description": "",
"main": "index.js",
"main": "Problem01.js",
"scripts": {
"test": "jest"
},
Expand Down