Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 70 additions & 10 deletions strangerStrings/StrangerStrings.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,95 @@
class StrangerStrings {

getHelloWorld(){
return null;
return "Hello World"
}

concatenation(firstSegment, secondSegment){
return null;
return firstSegment + secondSegment;
}

getPrefix(input){
return null;
let output = ""
for(let i = 0; i < input.length; i++){
output += input[i]
if(i === 2){
break
}

}
return output
}

getSuffix(input){
return null;
// return input[0] + input[1] + input[3]
// return input.substring(0,3);
return input[input.length-3] + input[input.length-2] + input[input.length-1]
}

getMiddleCharacter(input){
return null;
let x = input.length / 2;
if (x % 2 === 0) {
return input[x];
} else {
return input[Math.floor(x)];
}

}

getFirstWord(input){
return null;
// create variable to store output
// gather first set of characters into var
// break loop at first space
let output = ""
for (let i = 0; i < input.length; i ++){
output += input[i];

if (input[i + 1] === " "){
break
}
}
return output;
}

getSecondWord(spaceDelimnatedInput){
return null;
}
getSecondWord(input){
// create var to store output
// go through each char until a space is reached
// add each character after a space to the output
// return output
let output = ""
for(let i = 0; i < input.length; i ++){
if(input[i - 1] === " "){
output += input[i]
i++
output += input[i]
i++
output += input[i]
i++
output += input[i]
// I know i could use another loop here. I tried a couple cases where "for(let j = i)" to start
// the 2nd loop where the 1st left off but at this time I couldnt figure that out. I will work a little more on it.


}

}


return output
}



reverse(input){
return null;
// create var for output
// check for characters starting at the end of string
// add char to output var
// retunr output
let output = ""
for(let i = input.length - 1; i >= 0; i --){
output += input[i]
}
return output
}
}

Expand Down
20 changes: 10 additions & 10 deletions strangerStrings/StrangerStrings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -72,44 +72,44 @@ test("return the middle character of `inputValue`", () => {
expect(actual).toEqual(expected);
});

test("return the first sequence of characters", () => {
test("return the first sequence of characters of `input`", () => {
// Given
let strangerStrings = new StrangerStrings();
let inputValue = 'Wutang Clan';
let input = 'Wutang Clan';

let expected = "Wutang";


// When
let actual = strangerStrings.getFirstWord(inputValue);
let actual = strangerStrings.getFirstWord(input);
//Then
expect(actual).toEqual(expected);
});

test("return the second sequence of characters", () => {
test("return the second sequence of characters of `input`", () => {
// Given
let strangerStrings = new StrangerStrings();
let inputValue = 'Wutang Clan';
let input = 'Wutang Clan';

let expected = "Clan";


// When
let actual = strangerStrings.getSecondWord(inputValue);
let actual = strangerStrings.getSecondWord(input);
//Then
expect(actual).toEqual(expected);
});

test("return the reverse of input", () => {
// Given
let strangerStrings = new StrangerStrings();
let inputValue = 'WutangClan';
let input = 'WutangClan';

let expected = "nalCgnatuW";


// When
let actual = strangerStrings.reverse(inputValue);
let actual = strangerStrings.reverse(input);
//Then
expect(actual).toEqual(expected);
});