I am struggling with a JavaScript test, my answer isn't passing and I can't see why? Here's the question:
Write a function that returns the reverse of a given string. Although many languages have a built in function to reverse a string, you should do it manually, building up the output character by character. For example, "Hello" returns "olleH"
And this is what I have so far...
stringReverse = function(input) {
// Your code goes here
var inputA = input.split('');
var inputL = inputA.length;
var beta = new Array(inputL);
for (var i=0; i<inputL; i++) {
var alpha = inputA.pop();
beta.splice(i,1,alpha);
}
var newStr = beta.join('');
return console.log(newStr);
};
My output looks correct, however it isn't passing the tests. I get the following message:
Started
olleH FA F F Failures: 1) SolutionTests Test1 Message: Expected undefined to equal 'olleH'. Stack: Error: Expected undefined to equal 'olleH'. at Object. (/sandboxes/deer/SolutionSpec.js:7:40) 2) SolutionTests Test2 Message: Expected undefined to equal 'A'. Stack: Error: Expected undefined to equal 'A'. at Object. (/sandboxes/deer/SolutionSpec.js:11:36) 3) SolutionTests Test3 Message: Expected undefined to equal ''. Stack: Error: Expected undefined to equal ''. at Object. (/sandboxes/deer/SolutionSpec.js:15:35) 3 specs, 3 failures Finished in 0.014 seconds
Thank you!