Reverse a String Algorithm

Reverse a String Algorithm
0

#1

Tell us what’s happening:

how is posible that writing these piece of code function reverseString(str) {
return str.split(’’).reverse().join(’’);
} you get the test right taking into account that in any moment you write the variables : “hello”, and “Greetings from Earth”. I mean we shouldn´t store these variable first?.

thank you guys.

Your code so far

function reverseString(str) {
  return str;
}

reverseString("hello");

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36.

Link to the challenge:


#2

“hello” and “Greetings from Earth” are string values. You can pass any value into a function. The line reverseString(“hello”) is a call to the function reverseString with the string “hello” as an argument.

What you may be confusing is the fact that when you declare a function (like below), the functionParameterName is a variable and can only be a variable, because it is a placeholder for when you pass in a value to it.

function myFunction (functionParameterName) {
 // do some stuff
}