Refactoring firstReverse using each -
// trying refactor firstreverse function using each? // created func takes str parameter, use firstreverse within // loop output reversed version of string.
var stringname = "matt";
var firstreverse = function(str){ var output = ""; for(var = str.length -1; >= 0; i--){ output+= str[i]; } return output; };
firstreverse(stringname)
// output: "ttam"
something this?
var stringname="matt"; function firstreverse(str) { var newstring=""; str.split('').foreach(function(a){newstring=a+newstring}); return newstring; } document.getelementbyid('test')./*danger!!!*/innerhtml = firstreverse(stringname);
<div id="test"></div>
Comments
Post a Comment