PASSED ALL TESTS

This commit is contained in:
Fredrik Uddenfeldt 2023-05-17 22:00:23 +02:00
parent 70985047e3
commit fb96215bc6
2 changed files with 8 additions and 11 deletions

View File

@ -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;

View File

@ -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('')
}) })
}); });