diff --git a/basicMath/MathUtilities.js b/basicMath/MathUtilities.js index 705dd88..88bccf5 100644 --- a/basicMath/MathUtilities.js +++ b/basicMath/MathUtilities.js @@ -1,20 +1,20 @@ class MathUtilities { - add(baseValue, valueToAdd){ - return -1; + add(baseValue, valueToAdd) { + return baseValue + valueToAdd; } - subtract(baseValue, valueToAdd){ - return -1; + subtract(baseValue, valueToSubtract) { + return baseValue - valueToSubtract; } - divide(baseValue, valueToAdd){ - return -1; + divide(baseValue, valueToDivide) { + return baseValue / valueToDivide; } - multiply(baseValue, valueToAdd){ - return -1; + multiply(baseValue, valueToMultiply) { + return baseValue * valueToMultiply; } } 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/readme.md b/readme.md index 16d8d67..8376472 100644 --- a/readme.md +++ b/readme.md @@ -10,4 +10,16 @@ Then run ``` npm install -``` \ No newline at end of file +``` + +find the total number of indices +divide that by 2 +if total number is odd, return 2 middle indices +return that character + + + +find the total number of words by counting the spaces between +if there's a space, break the loop +put characters before space into a variable +return variable diff --git a/strangerStrings/StrangerStrings.js b/strangerStrings/StrangerStrings.js index 7fb3629..8607caf 100644 --- a/strangerStrings/StrangerStrings.js +++ b/strangerStrings/StrangerStrings.js @@ -1,35 +1,43 @@ class StrangerStrings { - getHelloWorld(){ - return null; + getHelloWorld() { + return "Hello World"; } - concatenation(firstSegment, secondSegment){ - return null; + concatenation(firstSegment, secondSegment) { + return firstSegment + secondSegment; } - getPrefix(input){ - return null; + getPrefix(input) { + return input.substring(0, 3); } - getSuffix(input){ - return null; + getSuffix(input) { + return input[input.length - 3] + input[input.length - 2] + input[input.length - 1]; } - getMiddleCharacter(input){ - return null; + getMiddleCharacter(input) { + let x = input.length / 2; + if (x % 2 === 0) { + return input[x]; + } else { + return input[Math.floor(x)]; + } } - getFirstWord(input){ - return null; + getFirstWord(input) { + var firstWord = input.replace(/ .*/, ''); + return firstWord; } - - getSecondWord(spaceDelimnatedInput){ - return null; + + getSecondWord(spaceDelimnatedInput) { + const originalString = spaceDelimnatedInput; + const splitString = originalString.split(" "); + return splitString[1]; } - - reverse(input){ - return null; + + reverse(input) { + return input.split("").reverse().join(""); } } diff --git a/strangerStrings/StrangerStrings.test.js b/strangerStrings/StrangerStrings.test.js index 59da8fa..de59701 100644 --- a/strangerStrings/StrangerStrings.test.js +++ b/strangerStrings/StrangerStrings.test.js @@ -58,10 +58,10 @@ test("return the last 3 characters of `input`", () => { }); -test("return the middle character of `inputValue`", () => { +test("return the middle character of `input`", () => { // Given let strangerStrings = new StrangerStrings(); - let inputValue = 'MethodMan'; + let input = 'MethodMan'; let expected = "o";