As I said in the title, I want to make a function that receives an array and return all the elements in reverse order. I studied a lit bit of javascript, but this is bugging me for some time. I made two functions to make it clear, as even my friends didn't understand the concept, the second is the one who is bugging me.
const reverse = (pal) => {
var aux = "";
for(var i in pal){
aux = pal[i] + aux;
}
return aux;
}
console.log(reverse("are")); //=> returns "era"
This function above works fine and returns only one word, the next needs to return the array and all the words in reverse (just in case if someone didn't understand)
const reverPal = (pal) => {
let aux = "";
let aux1 = "";
for (var i in pal) {
aux += pal[i]
for (var i in aux.length) { //I think the problem starts here
aux.forEach((word) => {
word.reverse();
aux1 += word;
})
}
}
return aux1;
}
console.log(reverPal(["hello", "how", "are", "you"]));
//should return = "olleh", "woh", "era", "ouy"
//but returns nothing in this code
Can someone help me?