PASSED ALL TESTS
This commit is contained in:
parent
70985047e3
commit
fb96215bc6
|
@ -1,17 +1,14 @@
|
||||||
const reverseString = function(string) {
|
const reverseString = function(string) {
|
||||||
let num = string.length;
|
let num = string.length;
|
||||||
let lastLetter = string.slice(-1);
|
let lastLetter = string.slice(-1);
|
||||||
let secondLastLetter = string.slice(-2, -1);
|
for (let i = 1; i <= num; i++) {
|
||||||
let thirdLastLetter = string.slice(-3, -2);
|
|
||||||
let fourthLastLetter = string.slice(-4, -3);
|
|
||||||
let fifthLastLetter = string.slice(-5, -4);
|
|
||||||
|
|
||||||
/* for (let i = 0; i <= num; i++) { */
|
lastLetter += string.slice(((-i)-1), (-i));
|
||||||
return(lastLetter + secondLastLetter + thirdLastLetter + fourthLastLetter + fifthLastLetter)
|
|
||||||
|
|
||||||
|
}
|
||||||
|
return lastLetter;
|
||||||
|
|
||||||
|
}
|
||||||
};
|
|
||||||
|
|
||||||
// Do not edit below this line
|
// Do not edit below this line
|
||||||
module.exports = reverseString;
|
module.exports = reverseString;
|
||||||
|
|
|
@ -5,14 +5,14 @@ describe('reverseString', () => {
|
||||||
expect(reverseString('hello')).toEqual('olleh');
|
expect(reverseString('hello')).toEqual('olleh');
|
||||||
});
|
});
|
||||||
|
|
||||||
test.skip('reverses multiple words', () => {
|
test('reverses multiple words', () => {
|
||||||
expect(reverseString('hello there')).toEqual('ereht olleh')
|
expect(reverseString('hello there')).toEqual('ereht olleh')
|
||||||
})
|
})
|
||||||
|
|
||||||
test.skip('works with numbers and punctuation', () => {
|
test('works with numbers and punctuation', () => {
|
||||||
expect(reverseString('123! abc!')).toEqual('!cba !321')
|
expect(reverseString('123! abc!')).toEqual('!cba !321')
|
||||||
})
|
})
|
||||||
test.skip('works with blank strings', () => {
|
test('works with blank strings', () => {
|
||||||
expect(reverseString('')).toEqual('')
|
expect(reverseString('')).toEqual('')
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue