scrimba
Solution for day 5 of #javascriptmas
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Solution for day 5 of #javascriptmas
AboutCommentsNotes
Solution for day 5 of #javascriptmas
Expand for more info
main.js
run
preview
console
function reverseAString(str) {
// Convert string to an array using split('')
// Reverse array using reverse()
// Convert array to string using join('')
let reversedString = ((str.split('')).reverse()).join('');
return reversedString;
}

// Alternative solution not using methods
/*
function reverseAString(str) {
var reversedString = "";
for (let i = str.length - 1; i >= 0; i--) {
reversedString += str[i];
}
return reversedString;
}
*/


/**
* Test Suite
*/
describe('reverseAString()', () => {
it('returns original string reversed', () => {
// arrange
const str = 'hello';

// act
const result = reverseAString(str);

// log
console.log("result: ", result);

// assert
expect(result).toBe('olleh');
});
});
Console
"result: "
,
"olleh"
,
/index.html
LIVE