From 46558dec3db7462985903a4a08d931a84b232fc2 Mon Sep 17 00:00:00 2001 From: SpringerJordan Date: Mon, 22 Feb 2021 12:13:53 -0500 Subject: [PATCH] first commit --- .vscode/launch.json | 18 +++++++++++++ Day01/Problem01.js | 63 +++++++++++++++++++++++++++++++++++---------- 2 files changed, 68 insertions(+), 13 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..e12c88d --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,18 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "skipFiles": [ + "/**" + ], + "program": "${workspaceFolder}/index.js" + } + ] +} \ No newline at end of file diff --git a/Day01/Problem01.js b/Day01/Problem01.js index 6ad3c39..24aadc5 100644 --- a/Day01/Problem01.js +++ b/Day01/Problem01.js @@ -1,13 +1,16 @@ 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. - */ + /** + * 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) { + + return input.split(" ").length; // code goes here - return null; + // return null; } @@ -17,7 +20,18 @@ class Problem { * */ letterCapitalize(str) { - return null; + + + let words = str.split(" "); + + for (let i = 0; i < words.length; i++) { + words[i] = words[i][0].toUpperCase() + words[i].substr(1); + } + + return words.join(" "); + + + } @@ -28,8 +42,12 @@ class Problem { * program should return the string sredoC dna dlroW olleH. */ - firstReverse(input){ - return null; + firstReverse(input) { + + return input.split("").reverse().join(""); + + + // return null; } /** @@ -39,8 +57,16 @@ class Problem { * input will not be empty. */ longestWord(input) { - // code goes here - return null; + var str = input.match(/\w[a-z]{0,}/gi); + var longest = 0; + var word = null; + str.forEach(function (str) { + if (longest < str.length) { + longest = str.length; + word = str; + } + }); + return word; } /** @@ -49,8 +75,19 @@ class Problem { * Let numbers and symbols stay the way they are. */ swapCase(str) { + let newStr = ""; + for (let i = 0; i < str.length; i++) { + if (str[i] === str[i].toLowerCase()) { + newStr += str[i].toUpperCase(); + } else { + newStr += str[i].toLowerCase(); + } + } + console.log(newStr); + return newStr; + // code goes here - return null; + // return null; } }