I write a function that inverts all the words, but the order of the words remains the same:
reverseWords ("This is an example!"); // returns "sihT si na! elpmaxe"
my code is:
function reverseWords(str) { // Go for it return str.split("").reverse().join(""); } reverseWords("This is an example!"); I get this: "! elpmaxe na si sihT" and you need to keep order, how?
splitinto array. We iterate over the array and for each element doreverse. Then we glue the array back through the gap. Everything. - Chubatiy