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..ba3e9cf 100644 --- a/strangerStrings/StrangerStrings.js +++ b/strangerStrings/StrangerStrings.js @@ -1,35 +1,74 @@ class StrangerStrings { getHelloWorld(){ - return null; + let helloWorld = "Hello World"; + return helloWorld } concatenation(firstSegment, secondSegment){ - return null; + return firstSegment + secondSegment; } getPrefix(input){ - return null; + let firstLetter = input[0] + let secondLetter = input[1] + let thirdLetter = input[2] + return firstLetter + secondLetter + thirdLetter; } getSuffix(input){ - return null; + // get the 3rd to last letter. + let thirdToLastLetter = input[input.length - 3]; + // get the 2nd letter. + let secondToLastLetter = input[input.length - 2]; + // get the last letter. + let lastLetter = input[input.length - 1]; + return thirdToLastLetter + secondToLastLetter + lastLetter; + } getMiddleCharacter(input){ - return null; + //get input length + let inputLength = input.length; + //divide length by two to cut in half. Math.floor to round down since string is an odd number. + let middle = Math.floor(inputLength / 2); + //return middle of input value. + if (inputLength % 2 == 0){ + // if even + return input[middle -1] + input[middle]; + } else { + return input[middle]; + } + } - getFirstWord(input){ - return null; + getFirstWord(inputValue){ + // split up the string using .split(). Turns a string into an array. + let x = inputValue.split(" "); + // get the first index of the array. + let firstWord = x[0]; + // return the first word. + return firstWord; } - getSecondWord(spaceDelimnatedInput){ - return null; + getSecondWord(inputValue){ + // turn input value into a string using .split() + let x = inputValue.split(" "); + // get the second index of the array. + let secondWord = x[1]; + // return the second word. + return secondWord; } - reverse(input){ - return null; + reverse(inputValue){ + // turn input value into a string using .split() + let x = inputValue.split(""); + // reverse the array using .reverse() + let strToArray = x.reverse(); + // turn the array back to a string with .join() + let backwardArray = strToArray.join(""); + // return joined reversed string. + return backwardArray; } } 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";