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
50 changes: 45 additions & 5 deletions StringsAndTings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,67 @@ class StringsAndTings {

// @return string with identical content, and the first character capitalized
camelCase(str){
return null;
let strSplit = str.split(" ");
for (let i=0; i < strSplit.length; i++){
let word = strSplit[i];
strSplit[i] = word[0].toUpperCase() + word.substring(1);
}

return strSplit.join(" ");
}

//@return string with identical contents, with each word individually in reverse order
reverseString(str){
return null;
let strSplit = str.split(" ");
for (let i=0; i < strSplit.length; i++) {
let word = strSplit[i];
strSplit[i] = word[i].toUpperCase() + word.substring(1);
}
return str.split("").reverse().join("");
}



// @return string with identical contents, in reverse order, with first character capitalized
reverseThenCamelCase(str){
return null;

let reverseCamel = this.reverseString(str);
return this.camelCase(reverseCamel);
}


// @return string with identical contents excluding first and last character
removeFirstAndLastCharacter(str){
return null;
let removeChar = str.substring(1, str.length-1);
return removeChar;
}

// @return string with identical characters, each with opposite casing
invertCasing(str){
return null;
let string = '';
let i = 0;
while (i < str.length) {
let n = str.charAt(i);
if (n == n.toUpperCase()) {
// *Call* toLowerCase
n = n.toLowerCase();
}else {
// *Call* toUpperCase
n = n.toUpperCase();
}
i += 1;
string += n;
}
return string;
}

reverseWords(str){
let words = str.split(" ");
let result ="";
for (let i = 0; i < words.length; i++) {
result += words[i].split('').reverse().join('') + " ";
}
return result.trim();
}
}

Expand Down
12 changes: 6 additions & 6 deletions StringsAndTings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test("camelCaseTest", () => {
let input = "she sells sea shells";
let expected = "She Sells Sea Shells";

let actual = stringsAndTings.camelCase(15);
let actual = stringsAndTings.camelCase(input);

expect(actual).toEqual(expected);
});
Expand All @@ -19,7 +19,7 @@ test("reverseTest", () => {
let input = "she sells sea shells";
let expected = "sllehs aes slles ehs";

let actual = stringsAndTings.camelCase(15);
let actual = stringsAndTings.reverseString(input);

expect(actual).toEqual(expected);
});
Expand All @@ -30,7 +30,7 @@ test("reverseWordsTest", () => {
let input = "she sells sea shells";
let expected = "ehs slles aes sllehs";

let actual = stringsAndTings.camelCase(15);
let actual = stringsAndTings.reverseWords(input);

expect(actual).toEqual(expected);
});
Expand All @@ -41,7 +41,7 @@ test("reverseThenCamelCaseTest", () => {
let input = "she sells sea shells";
let expected = "Sllehs Aes Slles Ehs";

let actual = stringsAndTings.camelCase(15);
let actual = stringsAndTings.reverseThenCamelCase(input);

expect(actual).toEqual(expected);
});
Expand All @@ -52,7 +52,7 @@ test("removeFirstAndLastCharacterTest", () => {
let input = "she sells sea shells";
let expected = "he sells sea shell";

let actual = stringsAndTings.camelCase(15);
let actual = stringsAndTings.removeFirstAndLastCharacter(input);

expect(actual).toEqual(expected);
});
Expand All @@ -64,7 +64,7 @@ test("invertCasingTest1", () => {
let input = "shE sells SEA sHeLlS";
let expected = "SHe SELLS sea ShElLs";

let actual = stringsAndTings.camelCase(15);
let actual = stringsAndTings.invertCasing(input);

expect(actual).toEqual(expected);
});
Expand Down
Loading