Tell us what’s happening:
Your code so far
function reverseString(str) {
return str;
}
reverseString("hello");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0
.
Challenge: Reverse a String
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-algorithm-scripting/reverse-a-string
Hi Guys,
My solution:
function reverseString( str ){
return str.split("").reverse().join("");
}
// simple
But my first attempt was :
function reverseS(str){
... let tam = str.length/2;
... for(let j =0; j<=tam; j++){
..... let aux =str[j];
..... str[j] = str[str.length-j-1];
..... str[str.length-j-1] = aux;
..... };
... return str;
... }
Although my cod don’t execution correct I don’t understant what happened.
This variable str is imutable in the function?