Completed exercise
This commit is contained in:
parent
c77a70db58
commit
b7591b11ff
|
@ -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;
|
||||||
|
|
|
@ -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