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

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -