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
145 changes: 145 additions & 0 deletions Day01/.loops.36.ques.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
class Problem {
/**
* Have the wordCount(input) take the str string parameter being passed
* and return the number of words the string contains
* (e.g. "Never eat shredded wheat or cake" would return 6). Words will be
* separated by single spaces.
*/

wordCount(input) {
// code goes here
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(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}

}
return null;
}



/**
* Have the function firstReverse(String input) take the input parameter being passed and
* return the string in reversed order. For example: if the input string is "Hello World and Coders" then your
* program should return the string sredoC dna dlroW olleH.
*/

function reverseString(str) {
var newString = "";
for (var i = str.length - 1; i >= 0; i--) {
newString += str[i];
}
return newString;
}
reverseString('hello');

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


/**
* Have the longestWord(String input) take the input parameter being passed and return the
* largest word in the string. If there are two or more words that are the same length,
* return the first word from the string with that length. Ignore punctuation and assume
* input will not be empty.
*/
longestWord (input)
// let splitString = input.split('');
// let Array = splitString.length ();
longestWord(input) {
// code goes here
let strSplit = input.split('');
let longestWord = 0;
for (let i = 0; i < strSplit.length; i++){
if(strSplit[i].length > longestWord){
longestWord = strSplit[i].length;
}
}
return longestWord;

longest = str => {
let words = str.split(" ");
let size = 0;
let max = [" "];
for (let i = 0; i < words.length; i++) {
if (words[i].length > size) {
size = words[i].length;
}
if (max[max.length - 1].length < words[i].length) {
max = [];
max.push(words[i]);
} else {
max = [...max, words[i]];
}
}
return max;
};

}

return sen;

}

// keep this function call here
console.log(LongestWord(readline())); // code goes here
return null;
}

/**
* 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) {
letterCapitalize(str) {
// 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;
}

return null;
}

}

module.exports = Problem;

letterCapitalize(string) {

return string.replace(/\w\S*/g, (w) => (w.replace(/^\w/, (c) => c.toUpperCase())));
}
69 changes: 58 additions & 11 deletions Day01/Problem01.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,48 @@ class Problem {
* separated by single spaces.
*/
wordCount(input) {
// code goes here
return null;
*/ wordCount(input) {
// code goes here
let string = input.split(' ');
let wordLength = string.length;
return wordLength;
} /**

}
}
return WordCounter;
}


/**
* 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(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
letterCapitalize(str) {
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 +58,10 @@ class Problem {
*/

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

/**
Expand All @@ -39,8 +71,17 @@ class Problem {
* 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;
}
}

/**
Expand All @@ -50,9 +91,15 @@ class Problem {
*/
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;