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

How to have a sharp product image?

How could Tony Stark make this in Endgame?

Will a top journal at least read my introduction?

How did Captain America manage to do this?

Are Boeing 737-800’s grounded?

How to verbalise code in Mathematica?

Why we can't write in air?

Why the difference in metal between 銀行 and お金?

A possible fake AI on Patreon!

Unexpected email from Yorkshire Bank

Any examples of headwear for races with animal ears?

How can I change the color of a part of a line?

How do Bards prepare spells?

Rivers without rain

How do we know that ממחרת השבת means from the first day of pesach and not the seventh?

How to creep the reader out with what seems like a normal person?

Realistic Necromancy?

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

Providence Pentominoes Puzzle By Andrew Bradburn (Jigsaw)

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

How exactly does Hawking radiation decrease the mass of black holes?

Error message with tabularx

Examples of subgroups where it's nontrivial to show closure under multiplication?

Please, smoke with good manners



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
    3 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
    3 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
    3 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
    3 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
3 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
3 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
    2 hours 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
    2 hours 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|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$













      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
        2 hours 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
        2 hours 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
        2 hours 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
        2 hours 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
        2 hours 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
        2 hours 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
        2 hours 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
        2 hours 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
      2 hours ago




      $begingroup$
      With the on-screen keyboard of my tablet.
      $endgroup$
      – Roland Illig
      2 hours 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
      2 hours 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
      2 hours 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 31 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|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|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$

                  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|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$



                  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|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 20 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

                      Saint-André (Pyrenaeus Orientalis) Nexus interni Nexus externi | Tabula navigationisOpenStreetMapGeoNames66168De hoc commune apud cassini.ehess.frHuius communis pagina interretialisAmplifica

                      Constantinus Vanšenkin Nexus externi | Tabula navigationisБольшая российская энциклопедияAmplifica

                      Montigny (Ligerula) Nexus interni Nexus externi | Tabula navigationisGeoNames45214Amplifica