title: Javascript string conversion and array sort
body: <p>I'm attempting a challenge on a JavaScript learning website.</p>
  
  <p>The instructions are:</p>
  
  <blockquote>
    <p>It was decided to attribute a "weight" to numbers. The weight of a
    number will be from now  on the sum of its digits For example 99 will
    have "weight" 18, 100 will have "weight" 1  so in the list 100 will
    come before 99. Given a string with the weights of FFC members  in
    normal order can you give this string ordered by "weights" of these
    numbers?</p>
    
    <p>Example:
         a = "56 65 74 100 99 68 86 180 90"ordered by numbers weights  becomes: "100 180 90 56 65 74 68 86 99" When two numbers have the same
    "weight",  let us class them as if they were strings and not numbers:
    100 is before 180 because  its "weight" (1) is less than the one of
    180 (9) and 180 is before 90 since, having the  same "weight" (9) it
    comes before as a string. All numbers in the list are  positive
    numbers and the list can be empty.</p>
  </blockquote>
  
  <p>My attempt is below:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function orderWeight(strng) {
  
    console.log(strng);
    if (strng === "") {
      return strng;
    } else {
      var arr = strng.split(" ").sort();
      console.log(arr);
      var keys = [];
  
      for (var i = 0; i &lt; arr.length; i++) {
        var weight = 0;
        var current = arr[i];
        //loop through the array adding the digits of each number
        for (var j = 0; j &lt; arr[i].length; j++) {
          var sNum = parseInt(arr[i].charAt[j]);
          weight += sNum;
          console.log(weight);
        }
        keys.push({
          weight: weight,
          number: current
        });
        console.log(keys);
      }
    }
  };</code></pre>
  </div>
  </div>
  </p>
  
  <p>The output from my code is:</p>
  
  <pre><code>input string "103 123 4444 99 2000"
  console.log(arr); = [ '103', '123', '2000', '4444', '99' ]
  console.log(weight); = NaN
  </code></pre>
  
  <p>I realise I will need to do more after I get this portion of code working but if someone could just point me in the direction of getting this part to do what I want I would much appreciate it.</p>