Reverse the word in a string with the same order in javascriptElegant function to “increase” a JavaScript string - for example, turning “aac” into “aad”Random weighted 'tick' functionSplit a String by an indexes arrayReturning Function Calls from an Array within a JavaScript FunctionRedacting everything in a string except a particular wordSimple string-split by root and sufix algorithmRecursive function that reverse the words in a stringProgram to reverse a string using std::stringSearch for longest substring in alphabetical order in a given stringReverse a string and change the position

What happened to Captain America in Endgame?

Single Colour Mastermind Problem

Is the 5 MB static resource size limit 5,242,880 bytes or 5,000,000 bytes?

Unexpected email from Yorkshire Bank

Is creating your own "experiment" considered cheating during a physics exam?

Sci-fi book: portals appear in London and send a failed artist towards a designated path where he operate a giant superweapon

Help to reproduce a tcolorbox with a decoration

How to figure out whether the data is sample data or population data apart from the client's information?

How come there are so many candidates for the 2020 Democratic party presidential nomination?

Do I have an "anti-research" personality?

How did Captain America manage to do this?

How would one muzzle a full grown polar bear in the 13th century?

Sci-fi novel series with instant travel between planets through gates. A river runs through the gates

Confused by chemical notation

A ​Note ​on ​N!

Pulling the rope with one hand is as heavy as with two hands?

Rivers without rain

What's the polite way to say "I need to urinate"?

What is the relationship between spectral sequences and obstruction theory?

(Java Minecraft 1.14) Was the Levels:n beacon tag removed/altered?

Killing undead fish underwater

Who and which - What to choose when we are referring to a choice between two or more things or persons

Mac Pro install disk keeps ejecting itself

How to get a plain text file version of a CP/M .BAS (M-BASIC) program?



Reverse the word in a string with the same order in javascript


Elegant function to “increase” a JavaScript string - for example, turning “aac” into “aad”Random weighted 'tick' functionSplit a String by an indexes arrayReturning Function Calls from an Array within a JavaScript FunctionRedacting everything in a string except a particular wordSimple string-split by root and sufix algorithmRecursive function that reverse the words in a stringProgram to reverse a string using std::stringSearch for longest substring in alphabetical order in a given stringReverse a string and change the position






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2












$begingroup$


I want reverse the string with the same order. We should not use the Array functions like split(), .reverse() and some other array functions also except array.length.



Here i am attached my code. How to achieve that thing more efficiently.



var str = "i am javascript";
// result "i ma tpircsavaj"
function reverseString(myStr)
var strlen = myStr.length, result = "", reverseStr = "", reverseStrArr = [];
for(var i = strlen-1; i >= 0; i--)
reverseStr += myStr[i];


for(var j = 0; j < strlen; j++)
if(reverseStr[j] == " ")
reverseStrArr.push(result);
result = "";
else
result += reverseStr[j];
if(j + 1 == strlen)
reverseStrArr.push(result);
result = "";




for(var k=reverseStrArr.length - 1; k >= 0; k--)
result += reverseStrArr[k] + " "

console.log(result);

reverseString(str);









share|improve this question







New contributor




Kallis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$











  • $begingroup$
    I think you want to keep the word order, of a string, but reverse each individual word in the string? Yes, the result of your code is "i ma tpircsavaj ".
    $endgroup$
    – KIKO Software
    2 hours ago

















2












$begingroup$


I want reverse the string with the same order. We should not use the Array functions like split(), .reverse() and some other array functions also except array.length.



Here i am attached my code. How to achieve that thing more efficiently.



var str = "i am javascript";
// result "i ma tpircsavaj"
function reverseString(myStr)
var strlen = myStr.length, result = "", reverseStr = "", reverseStrArr = [];
for(var i = strlen-1; i >= 0; i--)
reverseStr += myStr[i];


for(var j = 0; j < strlen; j++)
if(reverseStr[j] == " ")
reverseStrArr.push(result);
result = "";
else
result += reverseStr[j];
if(j + 1 == strlen)
reverseStrArr.push(result);
result = "";




for(var k=reverseStrArr.length - 1; k >= 0; k--)
result += reverseStrArr[k] + " "

console.log(result);

reverseString(str);









share|improve this question







New contributor




Kallis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$











  • $begingroup$
    I think you want to keep the word order, of a string, but reverse each individual word in the string? Yes, the result of your code is "i ma tpircsavaj ".
    $endgroup$
    – KIKO Software
    2 hours ago













2












2








2





$begingroup$


I want reverse the string with the same order. We should not use the Array functions like split(), .reverse() and some other array functions also except array.length.



Here i am attached my code. How to achieve that thing more efficiently.



var str = "i am javascript";
// result "i ma tpircsavaj"
function reverseString(myStr)
var strlen = myStr.length, result = "", reverseStr = "", reverseStrArr = [];
for(var i = strlen-1; i >= 0; i--)
reverseStr += myStr[i];


for(var j = 0; j < strlen; j++)
if(reverseStr[j] == " ")
reverseStrArr.push(result);
result = "";
else
result += reverseStr[j];
if(j + 1 == strlen)
reverseStrArr.push(result);
result = "";




for(var k=reverseStrArr.length - 1; k >= 0; k--)
result += reverseStrArr[k] + " "

console.log(result);

reverseString(str);









share|improve this question







New contributor




Kallis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$




I want reverse the string with the same order. We should not use the Array functions like split(), .reverse() and some other array functions also except array.length.



Here i am attached my code. How to achieve that thing more efficiently.



var str = "i am javascript";
// result "i ma tpircsavaj"
function reverseString(myStr)
var strlen = myStr.length, result = "", reverseStr = "", reverseStrArr = [];
for(var i = strlen-1; i >= 0; i--)
reverseStr += myStr[i];


for(var j = 0; j < strlen; j++)
if(reverseStr[j] == " ")
reverseStrArr.push(result);
result = "";
else
result += reverseStr[j];
if(j + 1 == strlen)
reverseStrArr.push(result);
result = "";




for(var k=reverseStrArr.length - 1; k >= 0; k--)
result += reverseStrArr[k] + " "

console.log(result);

reverseString(str);






javascript strings






share|improve this question







New contributor




Kallis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Kallis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Kallis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 3 hours ago









KallisKallis

1133




1133




New contributor




Kallis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Kallis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Kallis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • $begingroup$
    I think you want to keep the word order, of a string, but reverse each individual word in the string? Yes, the result of your code is "i ma tpircsavaj ".
    $endgroup$
    – KIKO Software
    2 hours ago
















  • $begingroup$
    I think you want to keep the word order, of a string, but reverse each individual word in the string? Yes, the result of your code is "i ma tpircsavaj ".
    $endgroup$
    – KIKO Software
    2 hours ago















$begingroup$
I think you want to keep the word order, of a string, but reverse each individual word in the string? Yes, the result of your code is "i ma tpircsavaj ".
$endgroup$
– KIKO Software
2 hours ago




$begingroup$
I think you want to keep the word order, of a string, but reverse each individual word in the string? Yes, the result of your code is "i ma tpircsavaj ".
$endgroup$
– KIKO Software
2 hours ago










3 Answers
3






active

oldest

votes


















3












$begingroup$

I would split this into two function, simply because they do different things:



First a simple string reverser:



function reverseString(input)

var output = "";
for(var i = input.length - 1; i >= 0; i--)
output += input[i];

return output;



This is an easy function that everybody can understand. But we need to reverse words, so we make another function for that.



function reverseWords(input)

var word = "", output = "";
for(var i = input.length - 1; i >= 0; i--)
if (input[i] == " ")
output += reverseString(word) + " ";
word = "";

else
word += input[i];


output += reverseString(word);
return output;



And that's it. Now this might not be the niftiest, or shortest, solution, but it is one that reasonably easy to understand, and you get two functions for the price of one.



Also notice that there's no erroneous space at the end anymore.






share|improve this answer









$endgroup$












  • $begingroup$
    And in two months, when someone discovers that emojis are destroyed when they are reversed, you only have a single small function that you need to repair instead of a large function. That's because the bug is clearly in the reverseString function since when you call reverseString("😃"), the result is wrong without reverseWords being involved at all.
    $endgroup$
    – Roland Illig
    2 hours ago










  • $begingroup$
    @RolandIllig Never thought of that, but yes, you're right. :-) :) How did you make that emoji?
    $endgroup$
    – KIKO Software
    2 hours ago











  • $begingroup$
    With the on-screen keyboard of my tablet.
    $endgroup$
    – Roland Illig
    1 hour ago










  • $begingroup$
    @RolandIllig My Windows 10 on-screen keyboard doesn't have emoji, but I can copy yours: 😃 Ah, I think this is simply an unicode character. Yes, I've got it!: 😎
    $endgroup$
    – KIKO Software
    1 hour ago










  • $begingroup$
    And then, one month later, another pedantic comes along and says that "AAu0308A" looks like "AÄA", but its reversed version puts the dots on one of the outer characters. And there you go, implementing all the trickery in reversing a string. The Swift programming language has these built-in, by the way. Many other programming languages lack decent string reversing support, simply because it's complicated and not needed often.
    $endgroup$
    – Roland Illig
    1 hour ago



















0












$begingroup$

:-)
Hello kallis,



Could please clarify why you don't want to put your string in an array ?



Indeed, you could use a call back function with a map method on an array of words.
The callback function would reverse each word, while keeping them at the same place in the sentence.






share|improve this answer








New contributor




SylviE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






$endgroup$




















    0












    $begingroup$

    let str = "I am Javascript" ; 
    const arrStr = (string) =>
    const string2 = string.split(' ') ;
    return string2 ;

    let strInArray = arrStr(str) ;
    strInArray = strInArray . map ( word =>
    let l = word.length ;
    let output = '' ;

    for (var i=l-1 ; i>=0 ; i--)
    output += word[i] ;


    return output ;

    // End of callback function
    ) ; // End of map method
    console.log(strInArray.join(' ')) ;`




    share








    New contributor




    SylviE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






    $endgroup$













      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "196"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );






      Kallis is a new contributor. Be nice, and check out our Code of Conduct.









      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f219293%2freverse-the-word-in-a-string-with-the-same-order-in-javascript%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      3












      $begingroup$

      I would split this into two function, simply because they do different things:



      First a simple string reverser:



      function reverseString(input)

      var output = "";
      for(var i = input.length - 1; i >= 0; i--)
      output += input[i];

      return output;



      This is an easy function that everybody can understand. But we need to reverse words, so we make another function for that.



      function reverseWords(input)

      var word = "", output = "";
      for(var i = input.length - 1; i >= 0; i--)
      if (input[i] == " ")
      output += reverseString(word) + " ";
      word = "";

      else
      word += input[i];


      output += reverseString(word);
      return output;



      And that's it. Now this might not be the niftiest, or shortest, solution, but it is one that reasonably easy to understand, and you get two functions for the price of one.



      Also notice that there's no erroneous space at the end anymore.






      share|improve this answer









      $endgroup$












      • $begingroup$
        And in two months, when someone discovers that emojis are destroyed when they are reversed, you only have a single small function that you need to repair instead of a large function. That's because the bug is clearly in the reverseString function since when you call reverseString("😃"), the result is wrong without reverseWords being involved at all.
        $endgroup$
        – Roland Illig
        2 hours ago










      • $begingroup$
        @RolandIllig Never thought of that, but yes, you're right. :-) :) How did you make that emoji?
        $endgroup$
        – KIKO Software
        2 hours ago











      • $begingroup$
        With the on-screen keyboard of my tablet.
        $endgroup$
        – Roland Illig
        1 hour ago










      • $begingroup$
        @RolandIllig My Windows 10 on-screen keyboard doesn't have emoji, but I can copy yours: 😃 Ah, I think this is simply an unicode character. Yes, I've got it!: 😎
        $endgroup$
        – KIKO Software
        1 hour ago










      • $begingroup$
        And then, one month later, another pedantic comes along and says that "AAu0308A" looks like "AÄA", but its reversed version puts the dots on one of the outer characters. And there you go, implementing all the trickery in reversing a string. The Swift programming language has these built-in, by the way. Many other programming languages lack decent string reversing support, simply because it's complicated and not needed often.
        $endgroup$
        – Roland Illig
        1 hour ago
















      3












      $begingroup$

      I would split this into two function, simply because they do different things:



      First a simple string reverser:



      function reverseString(input)

      var output = "";
      for(var i = input.length - 1; i >= 0; i--)
      output += input[i];

      return output;



      This is an easy function that everybody can understand. But we need to reverse words, so we make another function for that.



      function reverseWords(input)

      var word = "", output = "";
      for(var i = input.length - 1; i >= 0; i--)
      if (input[i] == " ")
      output += reverseString(word) + " ";
      word = "";

      else
      word += input[i];


      output += reverseString(word);
      return output;



      And that's it. Now this might not be the niftiest, or shortest, solution, but it is one that reasonably easy to understand, and you get two functions for the price of one.



      Also notice that there's no erroneous space at the end anymore.






      share|improve this answer









      $endgroup$












      • $begingroup$
        And in two months, when someone discovers that emojis are destroyed when they are reversed, you only have a single small function that you need to repair instead of a large function. That's because the bug is clearly in the reverseString function since when you call reverseString("😃"), the result is wrong without reverseWords being involved at all.
        $endgroup$
        – Roland Illig
        2 hours ago










      • $begingroup$
        @RolandIllig Never thought of that, but yes, you're right. :-) :) How did you make that emoji?
        $endgroup$
        – KIKO Software
        2 hours ago











      • $begingroup$
        With the on-screen keyboard of my tablet.
        $endgroup$
        – Roland Illig
        1 hour ago










      • $begingroup$
        @RolandIllig My Windows 10 on-screen keyboard doesn't have emoji, but I can copy yours: 😃 Ah, I think this is simply an unicode character. Yes, I've got it!: 😎
        $endgroup$
        – KIKO Software
        1 hour ago










      • $begingroup$
        And then, one month later, another pedantic comes along and says that "AAu0308A" looks like "AÄA", but its reversed version puts the dots on one of the outer characters. And there you go, implementing all the trickery in reversing a string. The Swift programming language has these built-in, by the way. Many other programming languages lack decent string reversing support, simply because it's complicated and not needed often.
        $endgroup$
        – Roland Illig
        1 hour ago














      3












      3








      3





      $begingroup$

      I would split this into two function, simply because they do different things:



      First a simple string reverser:



      function reverseString(input)

      var output = "";
      for(var i = input.length - 1; i >= 0; i--)
      output += input[i];

      return output;



      This is an easy function that everybody can understand. But we need to reverse words, so we make another function for that.



      function reverseWords(input)

      var word = "", output = "";
      for(var i = input.length - 1; i >= 0; i--)
      if (input[i] == " ")
      output += reverseString(word) + " ";
      word = "";

      else
      word += input[i];


      output += reverseString(word);
      return output;



      And that's it. Now this might not be the niftiest, or shortest, solution, but it is one that reasonably easy to understand, and you get two functions for the price of one.



      Also notice that there's no erroneous space at the end anymore.






      share|improve this answer









      $endgroup$



      I would split this into two function, simply because they do different things:



      First a simple string reverser:



      function reverseString(input)

      var output = "";
      for(var i = input.length - 1; i >= 0; i--)
      output += input[i];

      return output;



      This is an easy function that everybody can understand. But we need to reverse words, so we make another function for that.



      function reverseWords(input)

      var word = "", output = "";
      for(var i = input.length - 1; i >= 0; i--)
      if (input[i] == " ")
      output += reverseString(word) + " ";
      word = "";

      else
      word += input[i];


      output += reverseString(word);
      return output;



      And that's it. Now this might not be the niftiest, or shortest, solution, but it is one that reasonably easy to understand, and you get two functions for the price of one.



      Also notice that there's no erroneous space at the end anymore.







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered 2 hours ago









      KIKO SoftwareKIKO Software

      2,152512




      2,152512











      • $begingroup$
        And in two months, when someone discovers that emojis are destroyed when they are reversed, you only have a single small function that you need to repair instead of a large function. That's because the bug is clearly in the reverseString function since when you call reverseString("😃"), the result is wrong without reverseWords being involved at all.
        $endgroup$
        – Roland Illig
        2 hours ago










      • $begingroup$
        @RolandIllig Never thought of that, but yes, you're right. :-) :) How did you make that emoji?
        $endgroup$
        – KIKO Software
        2 hours ago











      • $begingroup$
        With the on-screen keyboard of my tablet.
        $endgroup$
        – Roland Illig
        1 hour ago










      • $begingroup$
        @RolandIllig My Windows 10 on-screen keyboard doesn't have emoji, but I can copy yours: 😃 Ah, I think this is simply an unicode character. Yes, I've got it!: 😎
        $endgroup$
        – KIKO Software
        1 hour ago










      • $begingroup$
        And then, one month later, another pedantic comes along and says that "AAu0308A" looks like "AÄA", but its reversed version puts the dots on one of the outer characters. And there you go, implementing all the trickery in reversing a string. The Swift programming language has these built-in, by the way. Many other programming languages lack decent string reversing support, simply because it's complicated and not needed often.
        $endgroup$
        – Roland Illig
        1 hour ago

















      • $begingroup$
        And in two months, when someone discovers that emojis are destroyed when they are reversed, you only have a single small function that you need to repair instead of a large function. That's because the bug is clearly in the reverseString function since when you call reverseString("😃"), the result is wrong without reverseWords being involved at all.
        $endgroup$
        – Roland Illig
        2 hours ago










      • $begingroup$
        @RolandIllig Never thought of that, but yes, you're right. :-) :) How did you make that emoji?
        $endgroup$
        – KIKO Software
        2 hours ago











      • $begingroup$
        With the on-screen keyboard of my tablet.
        $endgroup$
        – Roland Illig
        1 hour ago










      • $begingroup$
        @RolandIllig My Windows 10 on-screen keyboard doesn't have emoji, but I can copy yours: 😃 Ah, I think this is simply an unicode character. Yes, I've got it!: 😎
        $endgroup$
        – KIKO Software
        1 hour ago










      • $begingroup$
        And then, one month later, another pedantic comes along and says that "AAu0308A" looks like "AÄA", but its reversed version puts the dots on one of the outer characters. And there you go, implementing all the trickery in reversing a string. The Swift programming language has these built-in, by the way. Many other programming languages lack decent string reversing support, simply because it's complicated and not needed often.
        $endgroup$
        – Roland Illig
        1 hour ago
















      $begingroup$
      And in two months, when someone discovers that emojis are destroyed when they are reversed, you only have a single small function that you need to repair instead of a large function. That's because the bug is clearly in the reverseString function since when you call reverseString("😃"), the result is wrong without reverseWords being involved at all.
      $endgroup$
      – Roland Illig
      2 hours ago




      $begingroup$
      And in two months, when someone discovers that emojis are destroyed when they are reversed, you only have a single small function that you need to repair instead of a large function. That's because the bug is clearly in the reverseString function since when you call reverseString("😃"), the result is wrong without reverseWords being involved at all.
      $endgroup$
      – Roland Illig
      2 hours ago












      $begingroup$
      @RolandIllig Never thought of that, but yes, you're right. :-) :) How did you make that emoji?
      $endgroup$
      – KIKO Software
      2 hours ago





      $begingroup$
      @RolandIllig Never thought of that, but yes, you're right. :-) :) How did you make that emoji?
      $endgroup$
      – KIKO Software
      2 hours ago













      $begingroup$
      With the on-screen keyboard of my tablet.
      $endgroup$
      – Roland Illig
      1 hour ago




      $begingroup$
      With the on-screen keyboard of my tablet.
      $endgroup$
      – Roland Illig
      1 hour ago












      $begingroup$
      @RolandIllig My Windows 10 on-screen keyboard doesn't have emoji, but I can copy yours: 😃 Ah, I think this is simply an unicode character. Yes, I've got it!: 😎
      $endgroup$
      – KIKO Software
      1 hour ago




      $begingroup$
      @RolandIllig My Windows 10 on-screen keyboard doesn't have emoji, but I can copy yours: 😃 Ah, I think this is simply an unicode character. Yes, I've got it!: 😎
      $endgroup$
      – KIKO Software
      1 hour ago












      $begingroup$
      And then, one month later, another pedantic comes along and says that "AAu0308A" looks like "AÄA", but its reversed version puts the dots on one of the outer characters. And there you go, implementing all the trickery in reversing a string. The Swift programming language has these built-in, by the way. Many other programming languages lack decent string reversing support, simply because it's complicated and not needed often.
      $endgroup$
      – Roland Illig
      1 hour ago





      $begingroup$
      And then, one month later, another pedantic comes along and says that "AAu0308A" looks like "AÄA", but its reversed version puts the dots on one of the outer characters. And there you go, implementing all the trickery in reversing a string. The Swift programming language has these built-in, by the way. Many other programming languages lack decent string reversing support, simply because it's complicated and not needed often.
      $endgroup$
      – Roland Illig
      1 hour ago














      0












      $begingroup$

      :-)
      Hello kallis,



      Could please clarify why you don't want to put your string in an array ?



      Indeed, you could use a call back function with a map method on an array of words.
      The callback function would reverse each word, while keeping them at the same place in the sentence.






      share|improve this answer








      New contributor




      SylviE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      $endgroup$

















        0












        $begingroup$

        :-)
        Hello kallis,



        Could please clarify why you don't want to put your string in an array ?



        Indeed, you could use a call back function with a map method on an array of words.
        The callback function would reverse each word, while keeping them at the same place in the sentence.






        share|improve this answer








        New contributor




        SylviE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






        $endgroup$















          0












          0








          0





          $begingroup$

          :-)
          Hello kallis,



          Could please clarify why you don't want to put your string in an array ?



          Indeed, you could use a call back function with a map method on an array of words.
          The callback function would reverse each word, while keeping them at the same place in the sentence.






          share|improve this answer








          New contributor




          SylviE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






          $endgroup$



          :-)
          Hello kallis,



          Could please clarify why you don't want to put your string in an array ?



          Indeed, you could use a call back function with a map method on an array of words.
          The callback function would reverse each word, while keeping them at the same place in the sentence.







          share|improve this answer








          New contributor




          SylviE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          share|improve this answer



          share|improve this answer






          New contributor




          SylviE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          answered 13 mins ago









          SylviESylviE

          11




          11




          New contributor




          SylviE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





          New contributor





          SylviE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






          SylviE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





















              0












              $begingroup$

              let str = "I am Javascript" ; 
              const arrStr = (string) =>
              const string2 = string.split(' ') ;
              return string2 ;

              let strInArray = arrStr(str) ;
              strInArray = strInArray . map ( word =>
              let l = word.length ;
              let output = '' ;

              for (var i=l-1 ; i>=0 ; i--)
              output += word[i] ;


              return output ;

              // End of callback function
              ) ; // End of map method
              console.log(strInArray.join(' ')) ;`




              share








              New contributor




              SylviE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.






              $endgroup$

















                0












                $begingroup$

                let str = "I am Javascript" ; 
                const arrStr = (string) =>
                const string2 = string.split(' ') ;
                return string2 ;

                let strInArray = arrStr(str) ;
                strInArray = strInArray . map ( word =>
                let l = word.length ;
                let output = '' ;

                for (var i=l-1 ; i>=0 ; i--)
                output += word[i] ;


                return output ;

                // End of callback function
                ) ; // End of map method
                console.log(strInArray.join(' ')) ;`




                share








                New contributor




                SylviE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






                $endgroup$















                  0












                  0








                  0





                  $begingroup$

                  let str = "I am Javascript" ; 
                  const arrStr = (string) =>
                  const string2 = string.split(' ') ;
                  return string2 ;

                  let strInArray = arrStr(str) ;
                  strInArray = strInArray . map ( word =>
                  let l = word.length ;
                  let output = '' ;

                  for (var i=l-1 ; i>=0 ; i--)
                  output += word[i] ;


                  return output ;

                  // End of callback function
                  ) ; // End of map method
                  console.log(strInArray.join(' ')) ;`




                  share








                  New contributor




                  SylviE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






                  $endgroup$



                  let str = "I am Javascript" ; 
                  const arrStr = (string) =>
                  const string2 = string.split(' ') ;
                  return string2 ;

                  let strInArray = arrStr(str) ;
                  strInArray = strInArray . map ( word =>
                  let l = word.length ;
                  let output = '' ;

                  for (var i=l-1 ; i>=0 ; i--)
                  output += word[i] ;


                  return output ;

                  // End of callback function
                  ) ; // End of map method
                  console.log(strInArray.join(' ')) ;`





                  share








                  New contributor




                  SylviE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.








                  share


                  share






                  New contributor




                  SylviE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  answered 2 mins ago









                  SylviESylviE

                  11




                  11




                  New contributor




                  SylviE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.





                  New contributor





                  SylviE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






                  SylviE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.




















                      Kallis is a new contributor. Be nice, and check out our Code of Conduct.









                      draft saved

                      draft discarded


















                      Kallis is a new contributor. Be nice, and check out our Code of Conduct.












                      Kallis is a new contributor. Be nice, and check out our Code of Conduct.











                      Kallis is a new contributor. Be nice, and check out our Code of Conduct.














                      Thanks for contributing an answer to Code Review Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      Use MathJax to format equations. MathJax reference.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f219293%2freverse-the-word-in-a-string-with-the-same-order-in-javascript%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Era Viking Índice Início da Era Viquingue | Cotidiano | Sociedade | Língua | Religião | A arte | As primeiras cidades | As viagens dos viquingues | Viquingues do Oeste e Leste | Fim da Era Viquingue | Fontes históricas | Referências Bibliografia | Ligações externas | Menu de navegação«Sverige då!»«Handel I vikingetid»«O que é Nórdico Antigo»Mito, magia e religião na volsunga saga Um olhar sobre a trajetória mítica do herói sigurd«Bonden var den verklige vikingen»«Vikingatiden»«Vikingatiden»«Vinland»«Guerreiras de Óðinn: As Valkyrjor na Mitologia Viking»1519-9053«Esculpindo símbolos e seres: A arte viking em pedras rúnicas»1679-9313Historia - Tema: VikingarnaAventura e Magia no Mundo das Sagas IslandesasEra Vikinge

                      What's the metal clinking sound at the end of credits in Avengers: Endgame?What makes Thanos so strong in Avengers: Endgame?Who is the character that appears at the end of Endgame?What happens to Mjolnir (Thor's hammer) at the end of Endgame?The People's Ages in Avengers: EndgameWhat did Nebula do in Avengers: Endgame?Messing with time in the Avengers: Endgame climaxAvengers: Endgame timelineWhat are the time-travel rules in Avengers Endgame?Why use this song in Avengers: Endgame Opening Logo Sequence?Peggy's age in Avengers Endgame

                      Are there legal definitions of ethnicities/races? The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Legal definitions in the United StatesAre there truly legal limits on US interest rates?Are gender identity and sexual orientation federally protected?Why is there an apparent legal bias against digital services?What limits are there to the powers of individual judges in the United States legal system?Are women only scholarships legal under Irish / EU law?Is the term “race” defined by Public Law enacted by Congress of the United StatesIs there a legal definition of race in the US?Neighbors are spying for landlord on Renters is it legal?Are Protected Classes Bi-directional?