title: How to sort an array of odd numbers in ascending order, but keep even numbers at their position?
body: <p>I want to sort only odd numbers without moving even numbers. For example, when I write&nbsp;:</p>
  
  <pre class="lang-none prettyprint-override"><code>sortArray([5, 3, 2, 8, 1, 4])
  </code></pre>
  
  <p>The expected result is&nbsp;:</p>
  
  <pre class="lang-none prettyprint-override"><code>[1, 3, 2, 8, 5, 4]
  </code></pre>
  
  <p>I am new to JavaScript and I came across a challenge on the Internet that has me perplexed. I normally wouldn't post asking for a solution on the Internet, BUT I have tried for hours and I would like to learn this concept in JavaScript.</p>
  
  <p>The challenge states : </p>
  
  <p><em>You have an array of numbers.
  Your task is to sort ascending odd numbers but even numbers must be on their places.
  Zero isn't an odd number and you don't need to move it. If you have an empty array, you need to return it.</em></p>
  
  <p>Here is my code so far,  please take it easy on me I am in the beginning stages of programming.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function sortArray(array) {
    let oddNums = [];
    for(let i = 0; i &lt; array.length; i++) {
      if(array[i] % 2 !== 0) {
        oddNums.push(array[i]);
      }
    }
    oddNums = oddNums.sort((a,b)=&gt; a-b);
    array.concat(oddNums);
    array = array.sort((a,b) =&gt; a-b);
    return array;
  }</code></pre>
  </div>
  </div>
  </p>