Completed exercise

This commit is contained in:
Roberra0 2023-06-18 10:28:26 -07:00
parent c77a70db58
commit b7591b11ff
2 changed files with 20 additions and 4 deletions

View File

@ -1,6 +1,22 @@
const reverseString = function() { // Take in a word
// Split it into an array
// Pop array and store in a new array
// Continue until array is done
const reverseString = function(word) {
// Split it into an array
const ogStringArray = word.split("");
const length_ogStringArray = ogStringArray.length;
const reverseStringArray = [];
// console.log(charArray);
for (let i=0; i < length_ogStringArray; i++){
reverseStringArray.push(ogStringArray.pop());
}
return(reverseStringArray.join(""));
}; };
// reverseString("Roberra Aklilu");
// 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('')
}) })
}); });