title: Max-Mn Sum JavaScript HackerRank challenge
body: <p>Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly four of the five integers. Then print the respective minimum and maximum values as a single line of two space-separated long integers.</p>
  
  <p>For example <code>var arr = [1,3,5,7,9]</code> the output will be 16 24.</p>
  
  <p>Here is my solution.everything works except one case.When all element in the arr are equal my solutions returns error. How I can fix it?</p>
  
  <pre><code>function miniMaxSum(arr) {
      let largest = arr[0];
      let smallest = arr[0];
      let largestSum = 0;
      let smallestSum = 0;
      for(let i = 0; i &lt; arr.length; i ++){
        if(arr[i] &gt; largest){
          largest = arr[i];
        }
        if (arr[i] &lt; smallest){
          smallest = arr[i];
        }
      }
      for(let j = 0; j &lt; arr.length; j ++){
        if(arr[j] &lt; largest){
          smallestSum = smallestSum + arr[j];
        }
        if(arr[j] &gt; smallest){
          largestSum = largestSum + arr[j];
        }
      }
      console.log(smallestSum + " " + largestSum)
  }
  </code></pre>