diff --git a/StringsAndTings.js b/StringsAndTings.js index 4fdca47..b1e134e 100644 --- a/StringsAndTings.js +++ b/StringsAndTings.js @@ -2,28 +2,62 @@ 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 revStr = ""; + for( let i = str.length -1; i >= 0; i--) { + revStr += str[i]; + } + return revStr; + } + + //@return string with identical contents, with each word individually in reverse order + reverseWords(str){ + let revWords = str.split(" "); + for( let i = revWords.length -1; i >= 0; i--) { + revWords += str[i]; + } + return str.split("").reverse().join(""); } // @return string with identical contents, in reverse order, with first character capitalized reverseThenCamelCase(str){ - return null; + let revCamel = this.reverseString(str); + return this.camelCase(revCamel); } // @return string with identical contents excluding first and last character removeFirstAndLastCharacter(str){ - return null; + let result = str.substring(1, str.length-1); + return result; } // @return string with identical characters, each with opposite casing invertCasing(str){ - return null; + let invert = ""; + let i = 0; + while (i < str.length) { + let m = str.charAt(i); + if (m === m.toUpperCase()) { + m = m.toLowerCase(); + } else { + m = m.toUpperCase(); + } + i += 1 + invert += m; + } + return invert; } + + } module.exports = StringsAndTings; \ No newline at end of file diff --git a/StringsAndTings.test.js b/StringsAndTings.test.js index 689b63d..b5a06da 100644 --- a/StringsAndTings.test.js +++ b/StringsAndTings.test.js @@ -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); }); @@ -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); }); @@ -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); }); @@ -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); }); @@ -52,19 +52,18 @@ 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); }); - test("invertCasingTest1", () => { let stringsAndTings = new StringsAndTings(); 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); }); diff --git a/package.json b/package.json index 5ae2c26..38f3819 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,6 @@ "author": "Tariq Hook", "license": "ISC", "devDependencies": { - "jest": "^26.4.2" + "jest": "^26.6.3" } }