From 80681d55d1481a0c668140605e50475c6c617136 Mon Sep 17 00:00:00 2001 From: Stephanie Czetli Date: Wed, 13 Jan 2021 20:16:21 -0500 Subject: [PATCH 1/2] first commit; completed lab --- basicMath/MathUtilities.js | 8 +-- basicMath/MathUtilities.test.js | 2 +- strangerStrings/StrangerStrings.js | 67 +++++++++++++++++++------ strangerStrings/StrangerStrings.test.js | 9 ++-- 4 files changed, 61 insertions(+), 25 deletions(-) diff --git a/basicMath/MathUtilities.js b/basicMath/MathUtilities.js index 705dd88..5cdc657 100644 --- a/basicMath/MathUtilities.js +++ b/basicMath/MathUtilities.js @@ -2,19 +2,19 @@ class MathUtilities { add(baseValue, valueToAdd){ - return -1; + return baseValue + valueToAdd; } subtract(baseValue, valueToAdd){ - return -1; + return baseValue - valueToAdd; } divide(baseValue, valueToAdd){ - return -1; + return baseValue / valueToAdd; } multiply(baseValue, valueToAdd){ - return -1; + return baseValue * valueToAdd; } } diff --git a/basicMath/MathUtilities.test.js b/basicMath/MathUtilities.test.js index 2d37cf1..bf0c9b2 100644 --- a/basicMath/MathUtilities.test.js +++ b/basicMath/MathUtilities.test.js @@ -74,7 +74,7 @@ test("Test 2 Integer Division", () => { let addedValue = 1; // When - let expected = 127; + let expected = 2; let actual = math.divide(baseValue, addedValue); //Then expect(actual).toEqual(expected); diff --git a/strangerStrings/StrangerStrings.js b/strangerStrings/StrangerStrings.js index 7fb3629..b788f0c 100644 --- a/strangerStrings/StrangerStrings.js +++ b/strangerStrings/StrangerStrings.js @@ -1,35 +1,72 @@ class StrangerStrings { - getHelloWorld(){ - return null; + return "Hello World"; } concatenation(firstSegment, secondSegment){ - return null; + return firstSegment + secondSegment; } - getPrefix(input){ - return null; + getPrefix(input) { + //Goal: Get first 3 letters of the input word + // 1. Get the 1st letter + let firstLetter = input.charAt(0); + // 2. Get the 2nd letter + let secondLetter = input.charAt(1); + // 3. Get the 3rd letter + let thirdLetter = input.charAt(2); + // 4. Reassemble + let answer = firstLetter + secondLetter + thirdLetter; + return answer; + //return input.substring(0, 3); } - getSuffix(input){ - return null; + getSuffix(input) { + //Goal: Get last 3 letters of the input word + // return input.substring(input.length-3, input.length); + + // 1. Get the last letter + let firstLetter = input.charAt(input.length-1); + // // 2. Get the 2nd to the last letter + let secondLetter = input.charAt(input.length-2); + // // 3. Get the 3rd to the last letter + let thirdLetter = input.charAt(input.length-3); + // // 4. Reassemble + let answer = thirdLetter + secondLetter + firstLetter; + return answer; + // return thirdLetter + secondLetter + firstLetter; + } - getMiddleCharacter(input){ - return null; + getMiddleCharacter(inputValue) { + let position; + let length; + //If the word has an even number of characters divide by 2 + //Otherwise if the word has an odd number of characters length -1 and divide by 2 + if (inputValue.length % 2 == 0) { + position = inputValue.length / 2 - 1; + length = 2; + } else { + position = (inputValue.length - 1) / 2; + length = 1; } + return inputValue.substring(position, position + length); +} - getFirstWord(input){ - return null; + getFirstWord(inputValue) { + //return input.slice(input.length - 11,input.length - 5); + // return inputValue.substr[(0, )]; + let firstWord = inputValue.split(' '); + return firstWord[0]; } - getSecondWord(spaceDelimnatedInput){ - return null; + getSecondWord(inputValue){ + let secondWord = inputValue.split(' '); + return secondWord[1]; } - reverse(input){ - return null; + reverse(inputValue){ + return inputValue.split('').reverse('').join(''); } } diff --git a/strangerStrings/StrangerStrings.test.js b/strangerStrings/StrangerStrings.test.js index 59da8fa..270e36f 100644 --- a/strangerStrings/StrangerStrings.test.js +++ b/strangerStrings/StrangerStrings.test.js @@ -1,4 +1,4 @@ -const { TestScheduler } = require('jest'); +// const { TestScheduler } = require('jest'); const StrangerStrings = require('./StrangerStrings'); @@ -46,9 +46,9 @@ test("return the first 3 characters of `input`", () => { test("return the last 3 characters of `input`", () => { // Given let strangerStrings = new StrangerStrings(); - let input = 'Wutang'; + let input = 'WutangForever'; - let expected = "ang"; + let expected = "ver"; // When @@ -65,9 +65,8 @@ test("return the middle character of `inputValue`", () => { let expected = "o"; - // When - let actual = strangerStrings.getMiddleCharacter(input); + let actual = strangerStrings.getMiddleCharacter(inputValue); //Then expect(actual).toEqual(expected); }); From 78619aef3594cc466018e9052da66407ec4bbeb0 Mon Sep 17 00:00:00 2001 From: Stephanie Czetli Date: Wed, 13 Jan 2021 21:16:11 -0500 Subject: [PATCH 2/2] final commit --- strangerStrings/StrangerStrings.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/strangerStrings/StrangerStrings.js b/strangerStrings/StrangerStrings.js index b788f0c..85eda40 100644 --- a/strangerStrings/StrangerStrings.js +++ b/strangerStrings/StrangerStrings.js @@ -51,7 +51,7 @@ class StrangerStrings { length = 1; } return inputValue.substring(position, position + length); -} + } getFirstWord(inputValue) { //return input.slice(input.length - 11,input.length - 5); @@ -61,7 +61,7 @@ class StrangerStrings { } getSecondWord(inputValue){ - let secondWord = inputValue.split(' '); + let secondWord = inputValue.split(' '); return secondWord[1]; }