Sum without Highest and lower number js
<p>I'm trying to complete a kata inside codewars, but I'm having some problems. I would like to sum all elements inside an array except the <strong>highest</strong> and <strong>lower</strong> values.</p>

<p>This is what I have now</p>

<pre><code>function sumArray(array) {

  let largestVal =  Math.max(array);
  let lowestVal =  Math.min(array);
  let total =  0;

  let arrLength = array.length;

  console.log(`The lowest number is: ${lowestVal}`);
  console.log(`Array is: ${array}`);
  console.log(`Total is: ${total}`);
  console.log(`The larget number is: ${largestVal}`);
  return  // [QUESTION] &lt;= having problems in how to return the sum of each element except the largest and lowest values.  
}
</code></pre>

<p>Thanks in advance</p>

<p><strong>EDIT-1:</strong> Updated code with @WLatif implementation</p>

<pre><code>function validate(array) {
  if (typeof array === 'object' &amp;&amp; array instanceof Array &amp;&amp; array.length &gt; 1) {
    return 1;
  } else {
    return 0;
  }
}

function sumArray(array) {
  if (validate(array)) {
    let sorted = array.sort(function (a, b) { return a - b });
    let largestVal = sorted.slice(-1).pop();
    let lowestVal =  sorted[0];
    let total =  array.reduce( function(prev, curr) { return prev + curr; }, 0 );
    let arrLength = array.length;

    console.log(`The lowest number is: ${lowestVal}`);
    console.log(`Array is: ${array}`);
    console.log(`Total is: ${total}`);
    console.log(`The larget number is: ${largestVal}`);
    return (total- lowestVal - largestVal);
  } else {
    console.log(`Not a valid array`);
  }

}
</code></pre>

<p>This is the error I'm getting: </p>

<blockquote>
  <p>Not a valid array ✘ Expected: 0, instead got: undefined</p>
</blockquote>

<p>What am I missing? </p>

<p>Here are the instructions: </p>

<pre><code>Sum all the numbers of the array except the highest and the lowest element (the value, not the index!).
(Only one element at each edge, even if there are more than one with the same value!)

Example:

{ 6, 2, 1, 8, 10 } =&gt; 16
{ 1, 1, 11, 2, 3 } =&gt; 6


If array is empty, null or None, or if only 1 Element exists, return 0.
</code></pre>