solved reverseString exercises

This commit is contained in:
Salih 2020-07-16 00:50:36 +02:00
parent ffc0b766c8
commit 18d7b040d6
2 changed files with 9 additions and 5 deletions

View File

@ -1,5 +1,9 @@
const reverseString = function() { const reverseString = function(str) {
let rts='';
for (let index = str.length-1; index>=0; index--) {
rts=rts + str.substr(index,1);
}
return rts;
} }
module.exports = reverseString module.exports = reverseString

View File

@ -5,14 +5,14 @@ describe('reverseString', function() {
expect(reverseString('hello')).toEqual('olleh'); expect(reverseString('hello')).toEqual('olleh');
}); });
xit('reverses multiple words', function() { it('reverses multiple words', function() {
expect(reverseString('hello there')).toEqual('ereht olleh') expect(reverseString('hello there')).toEqual('ereht olleh')
}) })
xit('works with numbers and punctuation', function() { it('works with numbers and punctuation', function() {
expect(reverseString('123! abc!')).toEqual('!cba !321') expect(reverseString('123! abc!')).toEqual('!cba !321')
}) })
xit('works with blank strings', function() { it('works with blank strings', function() {
expect(reverseString('')).toEqual('') expect(reverseString('')).toEqual('')
}) })
}); });